请问你的java在线程里下载文件是怎么实现的?线程这方面我不大懂
展开全部
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
OutputStream o = response.getOutputStream();
byte b[] = new byte[1024];
// the file to download.
String directory = request.getParameter("csvLogDir");
String fileName = request.getParameter("csvLogName");
File fileLoad = new File(directory, fileName);
// the dialogbox of download file.
response.setHeader("Content-disposition", "attachment;filename="
+ fileName);
// set the MIME type.
response.setContentType("application/x-tar");
// get the file length.
long fileLength = fileLoad.length();
String length = String.valueOf(fileLength);
response.setHeader("Content_Length", length);
// download the file.
FileInputStream in = new FileInputStream(fileLoad);
int n = 0;
while ((n = in.read(b)) != -1) {
o.write(b, 0, n);
}
}
最简单的就是直接把a标签写成文件URL,哈哈哈,这个方法很淫荡的
throws IOException, ServletException {
OutputStream o = response.getOutputStream();
byte b[] = new byte[1024];
// the file to download.
String directory = request.getParameter("csvLogDir");
String fileName = request.getParameter("csvLogName");
File fileLoad = new File(directory, fileName);
// the dialogbox of download file.
response.setHeader("Content-disposition", "attachment;filename="
+ fileName);
// set the MIME type.
response.setContentType("application/x-tar");
// get the file length.
long fileLength = fileLoad.length();
String length = String.valueOf(fileLength);
response.setHeader("Content_Length", length);
// download the file.
FileInputStream in = new FileInputStream(fileLoad);
int n = 0;
while ((n = in.read(b)) != -1) {
o.write(b, 0, n);
}
}
最简单的就是直接把a标签写成文件URL,哈哈哈,这个方法很淫荡的
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询