struts上傳文件防止內存溢出

InputStream in  ;

FormFile myFile ;

FileOutputStream fos ;

myFile = filmBean.getDyljpc();                                       //上傳文件

 if (myFile != null) {
       in = myFile.getInputStream();             
       fos = new FileOutputStream(filmTypePc);           //上傳路徑
       byte buffer[] = new byte[10240];                              //開始向上傳路徑中剛建立的文件寫入數據,每次寫10KB字節               
       int count = 0;                            
       while ((count = in.read(buffer)) > 0) {      
       fos.write(buffer, 0, count);            
    }
    fos.flush();
    fos.close();
    myFile.destroy();                                    
 }

發佈了19 篇原創文章 · 獲贊 5 · 訪問量 3萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章