最近小弟发现用JAVA流的方式下载文件是出现了超过4G的文件就没法下载。查了网上说是文件硬盘的格式转化为NTFS。但是我的文件系统格式原本就是NTFS格式。另外,我怀疑是JVM 最大内存的原因,将JVM最大内调到了10G以上。还是不行,不知道各位XDJM有没有遇到这种情况。谢谢。
以下是下载代码:
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
OutputStream os = null;
InputStream is = null;
try {
File file = new File(path + strZipName);
if (!file.exists()) {
System.out.println("文件不存在");
}
is = new FileInputStream(file);
bis = new BufferedInputStream(is);
os = response.getOutputStream();
bos = new BufferedOutputStream(os);
response.setHeader("Pragma", "No-cache");
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", 0);
response.setContentType("application/x-msdownload;charset=utf-8");
response.setHeader("Content-disposition", "attachment;filename="
+ URLEncoder.encode(strZipName, "utf-8"));
int bytesRead = 0;
byte[] buffer = new byte[8192];
while ((bytesRead = bis.read(buffer, 0, 8192)) != -1) {
bos.write(buffer, 0, bytesRead);
}
bos.flush();
is.close();
bis.close();
os.close();
bos.close();
} catch (Exception e) {
e.printStackTrace();
}
以下是下载代码:
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
OutputStream os = null;
InputStream is = null;
try {
File file = new File(path + strZipName);
if (!file.exists()) {
System.out.println("文件不存在");
}
is = new FileInputStream(file);
bis = new BufferedInputStream(is);
os = response.getOutputStream();
bos = new BufferedOutputStream(os);
response.setHeader("Pragma", "No-cache");
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", 0);
response.setContentType("application/x-msdownload;charset=utf-8");
response.setHeader("Content-disposition", "attachment;filename="
+ URLEncoder.encode(strZipName, "utf-8"));
int bytesRead = 0;
byte[] buffer = new byte[8192];
while ((bytesRead = bis.read(buffer, 0, 8192)) != -1) {
bos.write(buffer, 0, bytesRead);
}
bos.flush();
is.close();
bis.close();
os.close();
bos.close();
} catch (Exception e) {
e.printStackTrace();
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货