展开全部
想要获得改过之后的文件名,必须重新新建file文件对象,示例如下:e68a84e8a2ad62616964757a686964616f31333337613134import java.io.*;
public class ReNameFile
{
public static void main(String[] args)
{
String file="E:/a/d.txt";// /不会出现不兼容问题
File path=new File(file);//新建一个file对象
try
{
if(!path.exists())
path.createNewFile();
}
catch(IOException e)//捕捉异常
{
System.out.println(e);
}
String pa=path.getPath();//得到文件路径
String filePath = pa.substring(0, pa.lastIndexOf("\\")); //获得上层路径
File newfile=new File(filePath+"\\qqq");//想要输出修改过后的文件名及全路径,要新建一个File对象
path.renameTo(newfile);//更改新路径
System.out.println("path.getName:"+path.getName()+" "+newfile.getName());
System.out.println("path.getPath:"+path.getPath()+" "+newfile.getPath());
}
}