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"); } } }