重命名文件或目录(renameTo)

    // File (or directory) with old name
    File file = new File();
    
    // File (or directory) with new name
    File file2 = new File();
    
    // Rename file (or directory)
    boolean success = file.renameTo(file2);
    if (!success) {
        // File was not successfully renamed
    }
经试用是可以更改文件和文件夹名字的,其它文件夹无论有没有子文件夹或文件
其实他还具有移动文件和文件夹的作用,不过,如果是文件夹,只能在同一个盘符下进行,我测试的是这样,不知为什么!

你可能感兴趣的:(J2EE)