java文件下载,中文不显示

    xiaoxiao2021-03-25  73

    @RequestMapping("/downLoadZipFile")     public void downLoadZipFile(String videoAddress, String videoName, HttpServletResponse response) throws Exception {         String filePath = PlatformConstants.IMG_CONTEXT_PATH + "/" + videoAddress;         URL url = new URL(filePath);         HttpURLConnection connection = (HttpURLConnection) url.openConnection();         DataInputStream is = new DataInputStream(connection.getInputStream());         String fileName = filePath.substring(filePath.lastIndexOf("/"));         String suffix = fileName.substring(fileName.lastIndexOf("."), fileName.length());         videoName = new String(videoName.getBytes(), "ISO-8859-1");         response.reset(); // 必要地清除response中的缓存信息         response.setHeader("Content-Disposition", "attachment; filename=" + videoName + suffix);         response.setContentType("application/octet-stream");// 根据个人需要,这个是下载文件的类型         javax.servlet.ServletOutputStream out = response.getOutputStream();         byte[] content = new byte[1024];         int length = 0;         while ((length = is.read(content)) != -1) {             out.write(content, 0, length);         }         out.write(content);         out.flush();         out.close();     }
    转载请注明原文地址: https://ju.6miu.com/read-38409.html

    最新回复(0)