邮件收取时,我把邮件信息上传到服务器,使用io操作,但如果3MB都会出现内存溢出 ,希望大家给点建议,怎么在读取时清除未使用内存
File storefile = new File(uploadPath+"/"+fileName);
BufferedOutputStream bos = null;
BufferedInputStream bis = null;
try {
bos = new BufferedOutputStream(new FileOutputStream(storefile));
bis = new BufferedInputStream(in);
while ( bis.read() != -1) {
bos.write(bis.read());
}
bos.flush();
} catch (Exception exception) {
throw new Exception("文件保存失败!");
} finally {
bos.close();
bis.close();
}
File storefile = new File(uploadPath+"/"+fileName);
BufferedOutputStream bos = null;
BufferedInputStream bis = null;
try {
bos = new BufferedOutputStream(new FileOutputStream(storefile));
bis = new BufferedInputStream(in);
while ( bis.read() != -1) {
bos.write(bis.read());
}
bos.flush();
} catch (Exception exception) {
throw new Exception("文件保存失败!");
} finally {
bos.close();
bis.close();
}
try {
bos = new BufferedOutputStream(new FileOutputStream(storefile));
bis = new BufferedInputStream(in);
byte[] buf=new byte[4096];
int len=-1
while ((len=bis.read(buf)) != -1) {
bos.write(buf,0,len);
}
} catch (Exception exception) {
throw new Exception("文件保存失败!");
} finally {
bos.close();
bis.close();
}