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 create a string of repeated characters? - September 1, 2023
- How do I convert datetime string with optional part to a date object? - August 28, 2023
- How do I split large excel file into multiple smaller files? - April 15, 2023