Java批量修改文件名的实例代码
import java.io.*;
import java.util.*;
public class test {
public static void main(string[] args) throws ioexception {
bufferedreader br = new bufferedreader(new filereader("output1.txt"));
list<string> newname = new arraylist<string>();
list<string> oldname = new arraylist<string>();
string line;
string[] col;
while((line=br.readline())!=null) {
col = line.split("#");
newname.add(col[0]);
oldname.add(col[1]);
}
br.close();
for(int i=0;i<newname.size();i++) {
file oldfile = new file("d:\\tddownload\\heihei\\"+oldname.get(i)+".mp4");
system.out.println(oldfile.exists());//看文件是否存在
file newfile = new file(oldfile.getparent()+file.separator+newname.get(i)+".mp4");
if(newfile.exists()) {
system.out.println(i+"已存在");//新文件已存在
} else {
system.out.println(i+"\t"+oldfile.renameto(newfile));//旧文件是否重命名成功
}
}
}
}