As a handsome (hard to force) of the student leaders, closely serving the people, this is not, after collecting the required photo file name + student number as required Student ID + name change
The fundamental difference between humans and animals is whether the use of tools, use the File class java batch operation, as follows:
Import java.io.File; / ** * @author Pandas * @date 2020/3/30 15:32 * @Version 1.0 * file name is: Wang sledgehammer _171060001.jpg * want to convert: 171060001_ king sledgehammer .jpg * / public class FileDo { public static void main (String [] args) { String dirName = "D: / photo / class photo *" ; File dir = new new File (dirName); File [] filesList = dir.listFiles (); // If the directory path exists and indeed IF (dir.exists () && dir.isDirectory ()) { for(File File: filesList) { // If the file in .jpg format IF ... "." (File.isFile () && file.getName () substring (file.getName () lastIndexOf ()) the equals ( "JPG. " )) { String fileName = file.getName (); String name = fileName.substring (0, fileName.lastIndexOf (" _ " )); String Number = fileName.substring (fileName.indexOf (" _ ") +. 1, fileName.lastIndexOf ( "." )); // rename the file name to be defined here as absolute virtual path file dest = new new file (dirName + "/"+number+"_"+name+".jpg" ); file.renameTo (); } } } } }
Conventionally doc oriented programming:
The official document: https://docs.oracle.com/javase/8/docs/api/
Speaking: http://www.matools.com/api/java8