从D目录下读取T1然后写到E目录

解决方案 »

  1.   

    public  void  copyallfile(String  path1,String  path2)  throws  IOException
      {
        File f=new File(path1);
        if(f.isDirectory() ){      File temp = new File(path2);
          if(!temp.isDirectory()) temp.mkdir();      File files[]=f.listFiles() ;
          for (int i = 0; i < files.length; i++) {
            if(!files[i].isDirectory())
            {
            FileInputStream fi = new FileInputStream(files[i].toString());
            FileOutputStream fo = new FileOutputStream(path2+"\\"+files[i].getName());
            byte date[] = new byte[fi.available()];
            fi.read(date);
            fo.write(date);
            fi.close();
            fo.close();
            }else
            {
              copyallfile(files[i].toString(),
                          path2+"\\"+files[i].getName());
            }
          }    }  }
      

  2.   

    pqds说的对,没有直接的方法。
      

  3.   

    import java.io.*;
    public  class  CopyFile  {  
       boolean  packFrame  =  false;  
     
       public  CopyFile()  {  
           copyDir(new  File("c:/temp"),new  File("c:/tmp"));  
           System.out.println(new  File("c:/tmp").getPath()+File.separator);  
       }  
     
       public  void  copyDir(File  src_path,File  dest_path){  
           File[]  files  =  src_path.listFiles();  
           for(int  i=0;i<files.length;i++){  
               File  src=files[i];  
               File  dest=new  File(dest_path.getPath()+File.separator+files[i].getName());  
               if(!src.isDirectory())  
                   copyFile(src,dest);  
           }  
       }  
     
       public  void  copyFile(File  src,File  dest){  
           try{  
               System.out.println(src.getAbsoluteFile()+"  ->  "+dest.getAbsoluteFile());  
               FileInputStream  in  =  new  FileInputStream(src);  
               FileOutputStream  out  =  new  FileOutputStream(dest);  
               byte[]  buffer  =  new  byte[1024];  
               int  length  =  -1;  
               while((length=in.read(buffer))!=-1){  
                               out.write(buffer,0,length);  
               }  
               out.flush();  
               out.close();  
               in.close();  
               System.out.println("文件复制成功!");  
           }catch(Exception  e){  
               System.out.println("文件复制失败!");  
           }  
       }  
         
       public  static  void  main(String[]  args)  {  
           CopyFile aa = new  CopyFile();  
       }  
    }