批量修改文件名java

package test0715;

import java.io.File;

public class FileRename {
public static void main(String[] args) {
File file=new File("f:/java/test");
String dirPath=file.getAbsolutePath();
System.out.println("dirPath: "+dirPath);
if(file.isDirectory()){
File[] files=file.listFiles();
long starttime=System.currentTimeMillis();
for(File fileFrom:files){
String fromFile=fileFrom.getName();
System.out.println("fromFile before: "+fromFile);
String toFileName;
int index;
index=fromFile.indexOf("p");
fromFile=fromFile.substring(index+1);
System.out.println("fromFile after: "+fromFile);

if(index!=-1){
toFileName=dirPath+"\\"+fromFile;
System.out.println("toFileName: "+toFileName);
File toFile=new File(toFileName);
if(fileFrom.exists()&&!toFile.exists()){
fileFrom.renameTo(toFile);
}
}
}
long endtime=System.currentTimeMillis();
System.out.println("Time:"+new Long(endtime-starttime));
}
}
}

批量修改文件名java,布布扣,bubuko.com

批量修改文件名java

上一篇:(java) Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.


下一篇:spring bean之间的关系:继承;依赖