programming-examples/java/Core_Java/Renaming a file.java

16 lines
471 B
Java
Raw Normal View History

2019-11-15 12:59:38 +01:00
Renaming a file
import java.io.*;
public class Rename {
public static void main(String[] argv) throws IOException {
// Construct the file object. Does NOT create a file on disk!
File f = new File("Rename.java'"); // backup of this source file.
// Rename the backup file to "junk.dat"
// Renaming requires a File object for the target.
f.renameTo(new File("junk.dat"));
}
}