package useful;
import java.io.File;
public class UpdateFileName {
public static void main(String[] args) {
UpdateFileName updateFileName = new UpdateFileName();
updateFileName.Update();
}
public void Update() {
//批量文件重命名
String path="D:/ccc";
File f = new File(path);
File[] files = f.listFiles();
for (int i = 0; i < files.length; i++) {
File a= files[i];
String s= a.getAbsolutePath();
if(!s.endsWith(".pdf")) {
updateFileName(s, s+".pdf");
}
}
}
public void updateFileName(String path1,String path2) {
File f1 = new File(path1);
File f2 = new File(path2);
if(f2.exists()) {
System.out.println("KK");
}
boolean r = f1.renameTo(f2);
if(r) {
System.out.println("success");
}else {
System.out.println("fail");
}
}
}