`
kt431128
  • 浏览: 36955 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

java文件拷贝

    博客分类:
  • java
 
阅读更多

private  void copy(File src, File dist) {  

       InputStream in = null;  

       BufferedOutputStream out = null;  

 

       try {  

           in = new BufferedInputStream(new FileInputStream(src), BUFFER_SIZE);  

           out = new BufferedOutputStream(new FileOutputStream(dist),BUFFER_SIZE);  

           byte[] buffer = new byte[16384];  

           int len = 0;  

           try {  

               while ((len=in.read(buffer)) > 0) {  

                   out.write(buffer, 0, len);  

               }

               

           } catch (IOException e) {  

               e.printStackTrace();  

           }  

       } catch (FileNotFoundException e) {  

           e.printStackTrace();  

       }finally{  

           if(null!=in){  

               try {  

                   in.close();  

               } catch (IOException e) {  

                   e.printStackTrace();  

               }  

           }  

           if(null!=out){  

               try {  

                   out.close();  

               } catch (IOException e) {  

                   e.printStackTrace();  

               }  

           }  

       }  

   }

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics