[英]How to read RESTFul webservice reponse ( zip file as a MediaType)?
当我点击服务URL时,它将给我一个ZIP文件,该文件需要移到某个位置。
请让我知道如何从Response中读取zip文件。 下面是我的代码。
@Path("/folder")
public class FileDownloadService {
@GET
@Path("zipFile")
@Produces("application/zip")
public Response getFile() {
File f = new File("/home/mpasala/Documents/Example.zip");
if (!f.exists()) {
throw new WebApplicationException(404);
} else {
Boolean success = moveFile();
}
return Response
.ok(f)
.header("Content-Disposition",
"attachment; filename=server.zip").build();
}
InputStream response = webResource.type(MediaType.MULTIPART_FORM_DATA_TYPE).post(InputStream.class,
formData);
OutputStream out = null;
int read = 0;
byte[] bytes = new byte[1024];
File file = new File("D:/Today/");
if (!file.exists()) {
file.mkdir();
out = new FileOutputStream(new File(file + ".zip"));
while ((read = response.read(bytes)) != -1) {
out.write(bytes, 0, read);
}
// new File(file +".zip").createNewFile();
} else {
out = new FileOutputStream(new File(file+ ".zip"));
while ((read = response.read(bytes)) != -1) {
out.write(bytes, 0, read);
}
}
out.flush();
out.close();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.