Java examples for File Path IO:Directory
Rename file or an empty directory
import java.io.*; public class Main { public static void main(String[] args) { File oldName = new File("C://Folder//source.txt"); File newName = new File("C://Folder//destination.txt"); boolean isFileRenamed = oldName.renameTo(newName); // w ww. jav a 2 s. co m if(isFileRenamed) System.out.println("File has been renamed"); else System.out.println("Error renaming the file"); } }