您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

Java 实例 - 文件重命名

2024/4/1 22:03:25发布23次查看
以下实例演示了使用 file 类的 oldname.renameto(newname) 方法来重命名文件:
/* 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 实例 - 文件重命名的内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product