标签:java
import java.io.File;
import java.io.IOException;
public class Rename {
public static void main(String[] args) throws IOException
{
File oldFile = new File("d:/1.Out");
if(!oldFile.exists())
{
oldFile.createNewFile();
}
System.out.println("修改前:"+oldFile.getName());
String rootPath = oldFile.getParent();
System.out.println("根路径是:"+rootPath);
File newFile = new File(rootPath + File.separator + "1.Out.back");
System.out.println("修改后:"+newFile.getName());
if (oldFile.renameTo(newFile))
{
System.out.println("修改成功!!!");
}
else
{
System.out.println("修改失败!!!");
}
}
}
标签:java
原文地址:http://8757576.blog.51cto.com/8747576/1615208