// File (or directory) to be moved
    File file = new File("filename");
    
    // Destination directory
    File dir = new File("directoryname");
    
    // Move file to new directory
    boolean success = file.renameTo(new File(dir, file.getName()));
    if (!success) {
        // File was not successfully moved
    }

解决方案 »

  1.   

    import  java.io.*;  
    class  copy_file  
    {  
       public  static  void  copyfile(String  path1,String  path2)  throws  IOException    //使用FileInputStream和FileOutStream  
       {  
           FileInputStream  fi=new  FileInputStream(path1);  
           FileOutputStream  fo=new  FileOutputStream(path2);  
           byte  data[]=new  byte[fi.available()];  
           fi.read(data);  
           fo.write(data);  
           fi.close();  
           fo.close();  
       }  
    }  
     
    public  class  joss  
    {  
       public  static  void  main(String  args[])  throws  IOException  
       {  
         copy_file.copyfile("f:\\1.jpg","f:\\2.jpg");  
       }  
    }  试试,可以看看FAQ!HAHA给分!
      

  2.   

    import java.io.*;public class doFile {
    public void copyfile(String str,String str1) throws FileNotFoundException {
    try {
    File file=new File(str);
    InputStream is=null;
    OutputStream os=null;
    byte[] b;
    File f=new File(str1);
    if(!file.isDirectory()) {
      is=new FileInputStream(str);
      b=new byte[is.available()];
      is.read(b);
      os=new FileOutputStream(str1);
      os.write(b);
      is.close();
      os.close();
      return;
    } else if(!f.exists())
      f.mkdirs();
    File[] filename=file.listFiles();
    for(int i=0;i<filename.length;i++) {
        copyfile(filename[i].getAbsolutePath(),str1+"/"+filename[i].getName());
    }
    } catch(IOException ex) {
    filecopycount++;
    System.out.println("filecopycount:"+String.valueOf(filecopycount));
    if(filecopycount<=5)
    copyfile(str,str1);
    System.err.println("err:"+ex.toString());
    }
    }
    }
    使用的时候,例如要将C:\1目录拷到D:\1,则
    doFile df=new doFile();
    df.copyfile("C:\\1","D:\\1");
    当然,拷单个文件也可
    df.copyfile("C:\\1\1.txt","D:\\1\\1.txt");
      

  3.   

    谢谢了! beyond_xiruo(又再次无奈的离开)你去
    我下面的帖子!我给你分!
    http://expert.csdn.net/Expert/topic/1813/1813783.xml?temp=9.513491E-02