Java 文件重命名
使用 File 类的 oldName.renameTo(newName) 方法来重命名文件
完整代码
import java.io.File;
public class Main {
public static void main(String[] args) {
File oldName = new File("C:/program.txt");
File newName = new File("C:/test.txt");
if(oldName.renameTo(newName)) {
System.out.println("已重命名");
} else {
System.out.println("Error");
}
}
}
结果输出
已重命名
还没有评论,来说两句吧...