您的位置:首页 > 其它

图片批量改名,那个renameTo方法折腾我一下午

2011-05-01 11:40 253 查看
import java.io.File;
import java.io.IOException;
public class FileJpgName {
public static void main(String [] args)throws IOException
{
loop("E://壁纸");
System.exit(0);
}
public static void loop(String dir)throws IOException
{
File f = new File(dir);
String str[] = null;
if(f.isDirectory())
{	int j = 0;
str = f.list();
for(int i=0;i<str.length;i++){
File file1 = new File(dir,str[i]);
if(str[i].endsWith(".jpg")){
j++;
String c = "ECH";
String s = Integer.toString(j);
String m = s.concat(".jpg");
String newname = c.concat(m);
if(file1.renameTo(new File(dir,newname)))
System.out.println("OK!!!");
else
System.out.println("Error!!!");

}
}
}
else{
System.out.println("NULL");
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: