各位老师,怎么编写一个JAVA程序,用来改变文件的 文件名,用代码怎么实现,先谢了

解决方案 »

  1.   

    e24. Renaming a File or Directory
        // File (or directory) with old name
        File file = new File("oldname");
        
        // File (or directory) with new name
        File file2 = new File("newname");
        
        // Rename file (or directory)
        boolean success = file.renameTo(file2);
        if (!success) {
            // File was not successfully renamed
        }
      

  2.   

    谢了那么要修改电脑里面的文件扩展名呢?
    怎么写呢
    用JAVA实现
    比如:我的电脑里有 扩展名为:txt的文件,想要把他修改为 exe的文件怎么写?
    拜托了
      

  3.   

    refile.bat   内容: 
    rename   D:\temp\test\*.txt   *.exe       
    String       command   =   "d:/temp/refile.bat";       
    Process   proc; 
    try   { 
    long       startTime       =       System.currentTimeMillis(); 
    proc   =   Runtime.getRuntime().exec(command); 
    if(proc.waitFor()!=0){       
    System.out.println("Command       Execution       Failed!");} 
    long       endTime       =       System.currentTimeMillis(); 
    long       totalTime       =   (endTime-startTime)/1000;       
    System.out.println("Take       Time:"+totalTime); 
    }   catch   (Exception   e)   { 
    //   TODO   Auto-generated   catch   block 
    e.printStackTrace();