日本免费全黄少妇一区二区三区-高清无码一区二区三区四区-欧美中文字幕日韩在线观看-国产福利诱惑在线网站-国产中文字幕一区在线-亚洲欧美精品日韩一区-久久国产精品国产精品国产-国产精久久久久久一区二区三区-欧美亚洲国产精品久久久久

java下載文件到本地 java下載文件( 二 )


@Controller
@RequestMapping("/download")
public class DownloadController {
@RequestMapping(path = "/output1")
public void output1(HttpServletRequest request, HttpServletResponse response) {
response.setCharacterEncoding("utf-8");
response.setContentType("application/octet-stream");
String filename = "案例案例.docx";
try {
filename = URLEncoder.encode(filename, "utf-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
//中文文件名需要編碼
response.setHeader("Content-Disposition", "attachment;filename=" + filename + "");
try {
String filePath = "C:\\\\Users\\\\admin\\\\Desktop\\\\案例案例.docx";
File file = new File(filePath);
response.setHeader("Content-Length", file.length() + "");
InputStream inputStream = new FileInputStream(file);
OutputStream outputStream = response.getOutputStream();
byte[] bytes = new byte[2048];
int r = -1;
while ((r = inputStream.read(bytes)) != -1) {
outputStream.write(bytes, 0, r);
}
outputStream.flush();
} catch (IOException e) {
e.printStackTrace();
}
}
【java下載文件到本地 java下載文件】}
(今完)

推薦閱讀