아래 코드를 사용하여 파일을 다운로드하고 있지만 작은 파일에는 문제가 없지만 크기가 11GB 이상인 파일을 다운로드하려고 시도 할 때 java.lang.NegativeArraySizeException
예외가 발생했습니다.파일 또는 zip 파일을 다운로드하는 자바 코드
public String downloadDirectory()
{
OutputStream myOut = null;
FileInputStream fileInputStream = null;
File downzip = new File(dirName+"/"+dir+".zip");
getServletResponse().setContentType("TEXT/HTML");
getServletResponse().setHeader("Content-Disposition","attachment; filename=\"" + dir +".zip" + "\"");
getServletResponse().setContentLength((int)downzip.length());
System.out.println("length "+(int)downzip.length());
//READ DATA FROM FILE
byte[] dataRead = new byte[(int)downzip.length()];
fileInputStream = new FileInputStream(downzip);
fileInputStream.read(dataRead,0,(int)downzip.length());
//WRITE DATA TO OUTFILE
myOut = getServletResponse().getOutputStream();
myOut.write(dataRead);
if (fileInputStream != null) {
fileInputStream.close();
}
}
catch(Exception e)
{
e.printStackTrace();
Execute.rmdirscript(dirName);
return "exception";
}
finally{
System.out.println("finally downloaddir");
if(myOut!=null){
try{
myOut.close();}
catch(Exception e){
e.printStackTrace();;
}
}
if (fileInputStream != null) {
try{
fileInputStream.close();}
catch(Exception e){
e.printStackTrace();;
}
}
}
}
오류가이 라인에있다 :
byte[] dataRead = new byte[(int)downzip.length()];
값 (int)downzip.length()
큰 파일 제외되고 java.lang.NegativeArraySizeException
예외를 준다.
을 파일에 최대에 그것을 사용했다? –
11GB는 너무 커서 int에 들어 가지 않습니다. 그리고 네 질문은 뭐니? –
다운로드를 다시 시작 하시길 바랍니다. 11GB를 통해 90 %의 길을 얻고 다시 시작해야하는 것은 다소 고통 스러울 것입니다. –