代码:
import java.io.File;
import java.io.IOException;
public class FileRename {
public static void main(String[] args) throws IOException
{
File file = new File("E:/path");
if (file == null) {
return;
}
if (file.isDirectory()) {
String newName;
String[] files = file.list();
for (int i = 0; i < files.length; i++) {
File f = new File(file, files[i]);
String name = f.getCanonicalPath();
newName = name.replace("W", "").replace("D", "").replace("+",
"-");
boolean b = f.renameTo(new
File(newName));
System.out.println(newName+"---b:"+b);
}
}
}
}
文件需放在FAT32文件系统磁盘中,否则可能修改不成功。原因待研究。。。