/* author by w3cschool.cc main.java */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:/java.txt"); if(oldname.renameto(newname)) { system.out.println("已重命名"); } else { system.out.println("error"); } }}
以上代码运行输出结果为(执行该程序前你可以先创建 program.txt 文件):
已重命名
以上就是java 实例 - 文件重命名的内容。
