@RequestMapping("/filedown1/{id}")
public void down(@PathVariable String id, HttpServletResponse response) throws Exception {
BudgetAttendance bugdet = new BudgetAttendance();
try {
bugdet = budgetAndAttendanceManageService.findBudgetById(new Long(id));
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
String fileName = bugdet.getFileName();
String filePath = bugdet.getFilePath();
String[] split = fileName.split("\\.");
int suffixIndex = split.length - 1;
String enctype = new String(split[suffixIndex].getBytes(), "ISO8859-1");
File file = realFile(fileName, filePath);
String fileCnName = new String(file.getName().getBytes("utf-8"), "
Java后端文件下载
于 2024-03-25 16:55:26 首次发布
这篇博客介绍了如何在Java后端实现文件下载功能。通过`@RequestMapping`和`@GetMapping`注解定义了两个不同的下载方法,分别处理不同情况的文件下载。内容包括读取文件,设置响应头,处理文件名编码问题,以及使用`BufferedInputStream`和`OutputStream`进行文件内容的传输。
摘要由CSDN通过智能技术生成