| 我这个复制多级文件夹有什么需要改进的地方,成是成功了,但我发现有点点别扭。复制代码public class Test7 {
        public static void main(String[] args) throws IOException {                   
           String s1 = "c://1";
           String s2 = "d://1";
           copyF(s1,s2);
           
        }
        public static void copyF(String oldpath,String newpath) throws IOException{
                   File f1 = new File(newpath);
                   if(!f1.exists())
                   {                           
                   f1.mkdirs();
                   }
                   File f2 = new File(oldpath);
                   File[] fi = f2.listFiles();
                   //File temp = null;
                   for(File f: fi){
                           if(f.isDirectory()){
                                   File f3 = new File(f1,f.getName());
                                   f3.mkdirs();
                                   copyF(f.getAbsolutePath(),f3.getAbsolutePath());
                                   //temp = new File(oldpath+File.separator+f.getName());
                                  // f1 = new File(temp.getName());
                                  // copyF(temp.getAbsolutePath(),f1.getAbsolutePath());
                           }
                           if(f.isFile()){
                                   BufferedInputStream bi =new BufferedInputStream
                                   (new FileInputStream(f));
                                   BufferedOutputStream bo = new BufferedOutputStream
                                   (new FileOutputStream(f1.getAbsolutePath()+File.separator+f.getName()));
                                   int i =0;
                                   while((i=bi.read())!=-1){
                                            bo.write(i);
                                            bo.flush();
                                   }
                                   bi.close();
                                   bo.close();
                           }
                           
                   }
        }
}
 
 
 |