import java.io.File; public class RenameFile { public static void main(String[] args) { File file = new File("C:\\MyFile.txt"); File newFile = new File("C:\\MyFileRenamed.txt"); file.renameTo(newFile); } }
This code will take the file 'MyFile.txt' and rename it 'MyFileRenamed.txt'
This can be used to rename any file on your computer.