文件名称:服务器下载文件
文件大小:4KB
文件格式:JAVA
更新时间:2022-05-20 10:31:40
下载文件
String file_unique = request.getParameter("file_unique"); String date = file_unique.substring(0,7); path = date+"/"+file_unique; System.out.println("--下载路径--:"+path); System.out.println("----"); System.out.println("--------"); //sPath = HttpRequest.forwardIn(restTemplate,"http://common-method/","getFileUrl",obj); InputStream fis=new BufferedInputStream(new FileInputStream(path)); System.out.println("----当前路径----"+new File(".").getAbsolutePath()); byte[] buffer = new byte[fis.available()]; fis.read(buffer); fis.close(); response.reset(); System.out.println("--输入流--:"+fis); System.out.println("----"); System.out.println("--------"); file_unique = new String(file_unique.getBytes(), "ISO-8859-1"); System.out.println("--下载文件名称--:"+file_unique); System.out.println("----"); System.out.println("--------"); response.addHeader("Content-Disposition","attachment;filename=" + file_unique); OutputStream toClient = new BufferedOutputStream(response.getOutputStream()); response.setContentType("application/octet-stream"); System.out.println("--输出流--:"+toClient); System.out.println("----"); System.out.println("--------"); toClient.write(buffer); System.out.println(buffer.toString()); toClient.flush(); toClient.close();