重命名文件或空目录
import java.io.*; public class Main {/**来 自 NowJava.com**/ 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); if(isFileRenamed) System.out.println("File has been renamed"); else System.out.println("Error renaming the file"); } /**来自 时 代 J a v a 公 众 号 - nowjava.com**/ }