Get some files after the filename is just number, also a txt description
Hey, who let us be programmers, make a small program change is old
Import Java.io.BufferedReader;
Import Java.io.File;
Import Java.io.FileReader;
Import java.io.IOException; public class Chengefilename {/** * Title: Using IO Stream to implement file batch modification name * Copyright:copyright (c) * @author: Beacon * Version 1.0 2012-09-24 * @throws ioexception * * public static void Main (string[] args) throws IOException {//
Gets the stream object of the file containing the file name FileReader fr = new FileReader ("F:\\programview\\java\\jdbc\\a.txt");
BufferedReader bfr = new BufferedReader (FR);
StringBuffer sb = new StringBuffer ();
Reads a string fname = NULL in a file line by row;
while ((Fname=bfr.readline ())!= null) {Sb.append (Fname.trim () + ",");
System.out.println (fname);
String sbname = sb.tostring ();
Gets the array of file names string[] Nfnames = Sbname.split (",");
/*for (int i = 0; i < nfnames.length; i++) {System.out.println (nfnames[i));
}*///Get the Folder object file = New file ("F:\\programview\\java\\jdbc\\view") that contains the file to be modified;
string[] fnames = null; if (!file.isfile ();& file.isdirectory ()) {//Get the filename to be modified fnames = File.list ();
/*for (int i = 0; i < fnames.length; i++) {System.out.println (fnames[i].substring (0, Fnames[i].lastindexof (".")); }*/}else{System.out.println ("non-file.")
"); for (int i = 0; i < fnames.length i++) {int index = Integer.parseint (fnames[i].substring 0, Fnames[i].lastin Dexof ("."))
-1;
Get a named file Object file Oldf = new file ("f:\\programview\\java\\jdbc\\view\\" +fnames[i));
Gets the file object for the new name file: Newf = new File ("f:\\programview\\java\\jdbc\\view\\" +nfnames[index]+ ". avi");
To rename Oldf.renameto (NEWF); } System.out.println ("rename completed.")
");
}
}
The code for the annotation section is just for testing;
Tip: If you want to modify the file name in this way, it's best to back up the file first. Otherwise it would be troublesome to make a mistake.