Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/389.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在java中使用rest客户端进行多文件下载_Java_Rest_Client - Fatal编程技术网

在java中使用rest客户端进行多文件下载

在java中使用rest客户端进行多文件下载,java,rest,client,Java,Rest,Client,我想从我的rest客户端保存多个文件。下面的代码将只保存一个文件,但我想它的多个文件 HttpResponse resp = client.execute(post); HttpEntity entity = resp.getEntity(); InputStream inStream = entity.getContent(); FileOutputStream outputStream = new FileOutputStream("MyContacts.xls"); int bytes

我想从我的rest客户端保存多个文件。下面的代码将只保存一个文件,但我想它的多个文件

HttpResponse resp = client.execute(post);
HttpEntity entity = resp.getEntity();

InputStream inStream = entity.getContent();
FileOutputStream outputStream = new FileOutputStream("MyContacts.xls");

int bytesRead = -1;
byte[] buffer = new byte[512];
while ((bytesRead = inStream.read(buffer)) != -1) {
     outputStream.write(buffer, 0, bytesRead);
}

您可以在一个文件夹中复制输入流。
您可以从流中读取N个字节,然后不读取()以重用流。

这是我的服务器端代码。public MultipartBody fetchExtractedImage()引发异常{List attachments=new LinkedList();File file1=new File(“D:\\attachments\\infiles\\db.jpg”);File file2=new File(“D:\\attachments\\infiles\\test.pdf”);如果(file1.isFile()&&file2.isFile()){attachments.add(新附件(file1.getName(),“application/octet stream”,file1));attachments.add(新附件(file2.getName(),“application/pdf”,file2));返回新的多部分正文(附件,true);}