@RequestMapping(value = "/download")
public void queryByDictType(HttpServletRequest request, HttpServletResponse response) {
String pathStr = request.getParameter("path")//文件路徑
response.addHeader("Content-type", "appllication/octet-stream");//下載標識
response.addHeader("Content-Disposition", "attachment;filename="+pathStr);////下載標識
try (InputStream in = new FileInputStream(fileName);
OutputStream out = response.getOutputStream()) {
int i;
while ((i = in.read()) != -1) {
out.write(i);
}
} catch (Exception e) {
}
}
javaWeb後端下載磁盤文件
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.