日期:2014-05-20 浏览次数:20768 次
File dir = new File("d:/test");
for (File dir1 : dir.listFiles()) {
if (dir1.isDirectory()) {
for (File file : dir1.listFiles()) {
if (file.getName().endsWith(".txt")) {
file.renameTo(new File(dir.getPath()+File.separator+"d"+file.getName()));
}
}
}
}
public static void main(String[] args) {
findAndMoveTo("d:/test","txt","123");
}
public static void findAndMoveTo(String path,String type,String prefix) {
File dir = new File(path);
for (File dir1 : dir.listFiles()) {
if (dir1.isDirectory()) {
for (File file : dir1.listFiles()) {
if (file.getName().endsWith(type)) {
file.renameTo(new File(dir.getPath()+File.separator+prefix+file.getName()));
file.delete();
}
}
}
}
}