The example of this article tells the method of renamed files in Java. Share it for everyone for your reference. The specifics are as follows:
There are always some information on the downloaded movies.
package sys.file; Import java.util.*; Import java.util.regex.matcher; Import java.util.regex.pattern; Import java.io.*; {PUBLIC Static Void Main (String ARGS [] [] ) {Zrename r = new zrename (); r.replace (); //r.changeorder ();} public void replace () {file dir = new file ("g: // movie // That year's rabbits those who rabbits those rabbits that year. Things [Original Edition]); // Write the replaced folder path here, pay attention to the use of double slash string [] files = dir.list (); file f = null; string filename = ""; // String OldName = "[Movie Paradise www.dygod.cn]" "; string oldName =" ""; // The part of the part to be replaced in the name is to replace in the name to be replaced by the name, it is the time when it is empty is the time. Delete For (String File: FILES) {f = new file (dir, file); // Note that if you must write it as a file (File) here, it must be filename = f.getName (); System.out.println (FILENAME); string s1 = "// d {4}. (Youku.com | Sohu Video)-"; zername r = new zrename (); (S1, FILENAME); OldName = R.Regex (S1, FILENAME); if (b) {//f.renameto.com (FL.Getabsolutepath () // "//"+FILENAME.Replace ("" Content "," content replaced "))))))); // Here you can use replace replacement repeatedly, of course, you can also use regular expressions to replace // Here you can use replace replacement repeatedly. Of course, you can also use regular expressions to use it. Replaced F.renameto (New File (Dir.getabsolutepath () + "//" // " + Filename.replace (OldName, News)); lutepath () + "//" + FILENAME.Substring (9));}}} System.exit (0);} Public void Changeorder () {file dir = new file ("g: // merge"); // Write the replaced folder path here. Pay attention to the use of double slope string [] files = dir.list (); file f = null; string filename = "" ""; // string oldName = "[Movie Paradise www.dygod. cn] "; string oldName =" "; // The part of the string newName =" ""; // The name to be replaced in the name is to delete the for (string file: files) {f = New File (DIR, FILE); // Note that if you must write it as a file (FL, FILE) here, if it is not operated as a file (file), it must be full path. Filename = f.getName (); (Filename); string s1 = "// d+"; zername r = new zrename (); boolean b = R.Regex1 (s1, filename); oldName = FILENAME; me)+"" " +filename; if (b) {//f.renameto (NEW FILE (FL.Getabsolutepath ()+"//" // "+FILENAME.RPlace (" Content to replace "," Replacement content "););)); // Here you can use replace replacement repeatedly. Of course, you can also use regular expressions to replace // Here you can use replace replacement repeatedly. Of course, you can also use regular expressions to replace F.renameto (New File (Dir.GetabsolutePath () + "//"+ filename.replace (oldName, Newname)); // Delete the former X bit //f.renameto to (New File (Dir.getabsolutepath () // "//"+ FILENAME.SUBSTRING (9). );}} System.exit (0);} // s1 regular expression to find, S2 find source public string regex (string s1, string s2) {pattern p = pattern.compile (s1); matcher m = p.Matcher (s2); Boolean result = m.find (); //system.out.println (Result); string s = ""; if (result) {s = m.group (); system.out. Println (s);} Return s;} // s1 regular expression to find, S2 find source Public Boolean regEx1 (String S1, String S2) {pattern p = pattern.compile (s1); (S2); BOOLEAN Result = m.find (); System.out.println (result); Return Result;}}It is hoped that this article is helpful to everyone's Java program design.