标签:iat dia name string stack osi mes query isp
文件下载:
@GET
@Path("/fileGet")
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces(MediaType.APPLICATION_OCTET_STREAM)
public Response getFile(@QueryParam("fileName") String fileName) {
String filepath = configs.getProperty("filePath");
String totalFile = filepath + File.separator + fileName;
logger.info("准备下载文件:" + totalFile);
File file = new File(totalFile);
long fileLength = file.length();
ResponseBuilder responseBuilder = Response.ok(file,
MediaType.APPLICATION_OCTET_STREAM);
responseBuilder.type("application/x-msdownload");
Response response = null;
try {
responseBuilder
.header("Content-Disposition", "attachment; filename="
+ URLEncoder.encode(getFileName(fileName), "UTF-8"));
responseBuilder.header("Content-Length", Long.toString(fileLength));
response = responseBuilder.build();
return response;
} catch (UnsupportedEncodingException e) {
logger.error("设置header失败:" + fileName);
e.printStackTrace();
}
return null;
}
标签:iat dia name string stack osi mes query isp
原文地址:https://www.cnblogs.com/mengziHEHE/p/9680927.html