Java 实例 - 文件重命名

Java 教程 · 2019-02-10 21:58:37

以下实例演示了使用 File 类的 oldName.renameTo(newName) 方法来重命名文件:

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 教程 文章: https://codercto.com/courses/l/12.html

查看所有标签

Learning Processing

Learning Processing

Daniel Shiffman / Morgan Kaufmann / 2008-08-15 / USD 49.95

Book Description Teaches graphic artists the fundamentals of computer programming within a visual playground! Product Description This book introduces programming concepts in the context of c......一起来看看 《Learning Processing》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

SHA 加密
SHA 加密

SHA 加密工具

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具