22-IO流-35-IO流(File对象-常见功能-重命名)

来源:互联网 发布:值得推荐的淘宝店铺 编辑:程序博客网 时间:2024/06/11 17:08
package demo;import java.io.File;public class FileMethodDemo3 {public static void main(String[] args) {/* * File对象的常见方法: * 4.重命名 * boolean renameTo(File dest) :重新命名文件。  *  */renameToDemo();}public static void renameToDemo() {//代码一File f1 = new File("c:\\0.txt");File f2 = new File("c:\\9.txt");f1.renameTo(f2);//原文件名是0,类型是txt,现在改成9.txt//代码二File f3 = new File("c:\\aa.txt");File f4 = new File("d:\\bb.txt");f3.renameTo(f4);//原文件aa.txt在c盘中,现在移动到d盘中且名称变为bb.txt,c盘中的原文件已消失(剪切+重命名)}}

0 0
原创粉丝点击