package org.kodejava.io;
import java.io.File;
import java.io.IOException;
public class FileRenameExample {
public static void main(String[] args) throws IOException {
// Creates a new file called OldHouses.csv
File oldFile = new File("OldHouses.csv");
boolean created = oldFile.createNewFile();
System.out.println("File created? " + created);
// Creates the target file.
File newFile = new File("NewHouses.csv");
// The renameTo() method renames file or directory to a
// new name by passing the new destination file.
boolean renamed = oldFile.renameTo(newFile);
System.out.println("File renamed? " + renamed);
}
}
Latest posts by Wayan (see all)
- How do I convert Map to JSON and vice versa using Jackson? - June 12, 2022
- How do I find Java version? - March 21, 2022
- How do I convert CSV to JSON string using Jackson? - February 13, 2022