java file copy

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 ();  

               }  

           }  

       }  

   }

Reproduced in: https: //my.oschina.net/kt431128/blog/224721

Guess you like

Origin blog.csdn.net/weixin_33724059/article/details/91952469