car
2017-01-07 11:04:25浏览 3294
public class FileSame {
public static void main(String[] args) {
String path="E:\\jar1";
File file = new File(path);
String[] strings = file.list();
String[] strings3=new String[strings.length];
char[] cs =null;
for (int i = 0; i < strings.length; ++i) {
cs = strings[i].toCharArray();
for (int j = cs.length-1; j >=0; --j) {
if (cs[j]=='5') {
cs[j]='6';
break;
}
}
strings3[i]=new String(cs);
}
String path2="E:\\jar2";
File file2 = new File(path2);
String[] strings2 = file2.list();
Arrays.sort(strings);
Arrays.sort(strings2);
Arrays.sort(strings3);
if (Arrays.equals(strings3, strings2)) {
for (int i = 0,j=0; i < strings.length&&j<strings2.length; ++i,++j) {
file=new File(path+File.separator+ strings[i]);
file2=new File(path+File.separator+ strings2[j]);
System.out.println(file.renameTo(file2));
}
}
}