HttpServletRequest request=getRequest();//獲取request對象緩存
ServletInputStream inputStream= request.getInputStream();//獲取輸入流性能
BufferedInputStream bis=new BufferedInputStream(inputStream);//轉化爲帶緩存區的輸入流對象
BufferedInputStream是帶緩衝區的輸入流,默認緩衝區大小是8M,可以減小訪問磁盤的次數,提升文件讀取性能get
file=new File("C:/work/1.jpg");//建立文件input
if(!file.exists()){
file.createNewFile();it
}file
BufferedOutputStream bos=new BufferedOutputStream(new FileOutputStream(file,true));request
//建立文件輸出流
byte[]b=new byte[1024];
int length=-1;
while((length=bis.read(b))!=-1){
bos.write(b, 0, length);
}
if(bis!=null){
bis.close();
}
if(bos!=null){
bos.close();
} 文件讀取