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("修改失败!!!");
}
}
}
本文转自lzf0530377451CTO博客,原文链接:http://blog.51cto.com/8757576/1615208 ,如需转载请自行联系原作者