发布网友
共2个回答
热心网友
package demo;
import java.io.File;
public class DemoApp {
public static void main(String[] args) throws Exception {
File oldFile = new File("E:\\Workspaces\\eclipse3.7\\Demo\\src\\test.txt");
if (!oldFile.exists()) {
oldFile.createNewFile();
}
System.out.println("修改前文件名称是:" + oldFile.getName());
String newFileName = oldFile.getName().substring(0,oldFile.getName().lastIndexOf("."));
File newFile = new File(newFileName);
System.out.println("修改后文件名称是:" + newFile.getName());
if (oldFile.renameTo(newFile)) {
System.out.println("修改成功!");
} else {
System.out.println("修改失败");
}
}
}
热心网友
路过,很想帮你但是我也不会