File f = new File("D:\temp\doc\type1"); f.renameTo(new File("D:\temp\doc\typea")); 这样可以。
renameTo public boolean renameTo(File dest)Renames the file denoted by this abstract pathname. Whether or not this method can move a file from one filesystem to another is platform-dependent. The return value should always be checked to make sure that the rename operation was successful. Parameters: dest - The new abstract pathname for the named file Returns: true if and only if the renaming succeeded; false otherwise Throws: SecurityException - If a security manager exists and its SecurityManager.checkWrite(java.lang.String) method denies write access to either the old or new pathnames NullPointerException - If parameter dest is null
f.renameTo(new File("D:\temp\doc\typea"));
这样可以。
public boolean renameTo(File dest)Renames the file denoted by this abstract pathname.
Whether or not this method can move a file from one filesystem to another is platform-dependent. The return value should always be checked to make sure that the rename operation was successful.
Parameters:
dest - The new abstract pathname for the named file
Returns:
true if and only if the renaming succeeded; false otherwise
Throws:
SecurityException - If a security manager exists and its SecurityManager.checkWrite(java.lang.String) method denies write access to either the old or new pathnames
NullPointerException - If parameter dest is null