在java中使用rest客户端进行多文件下载
我想从我的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
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);}