It's three steps, actually.
The first one to put the required file type, what file to find
File2.getname (). EndsWith (". txt") can determine what file to use with the suffix of the. txt name
Step Two
File File1 = new file ("Ceshi2", File2.getname ()); Initialize the required files
File File3 = new file ("Ceshi2", "Oracle" +File2.getname ()); Initialize the name of the file I want to modify
Step Three
Use Renameto to modify so that all the file names are modified.
PackageCn.oracle.file1;/*** Change the name of multiple files*/ImportJava.io.File; Public classFile2 { Public Static voidMain (string[] args) {//Initialize Find folderFile File =NewFile ("Ceshi2"); //return the contents of the folderfile[] Listfiles =File.listfiles (); //Traverse out for(File file2:listfiles) {//Find File if(File2.getname (). EndsWith (". txt")) {//Print to seeSystem.out.println (File2.getname ()); //Initialize the required filesFile file1 =NewFile ("Ceshi2", File2.getname ()); //Initialize the name of the file I want to modifyFile File3 =NewFile ("Ceshi2", "Oracle" +file2.getname ()); //ModifyFile1.renameto (FILE3); } } }}
Java modifies the names of multiple files