Use Java recursion to traverse the file under the folder, and then perform other operations on the file. such as: Rename the file, a class of files are re-encoded. All. java files under a project can be transcoded into utf-8, etc.
The code is as follows: Rename the file only
1 Packagecom.zhang.test;2 3 ImportJava.io.File;4 5 Public classGetFilePath {6 7 Public Static voidMain (string[] args) {8Getdirectory (NewFile ("e:/background map"));9 }Ten //Recursive traversal One Private Static voidgetdirectory (file file) { AFile flist[] =file.listfiles (); - if(Flist = =NULL|| Flist.length = = 0) { - return ; the } - for(File f:flist) { - if(F.isdirectory ()) { - //if it is a folder, continue + getdirectory (f); -}Else { + //all the files will be listed here A System.out.println (F.getabsolutepath ()); at /** - * In this case, you can rename the file or re-encode a class of files, such as: the. java files are transcoded into Utf-8 - */ - //file renaming examples such as the following -String filename=f.getname (); -String suffix= filename.substring (Filename.lastindexof (".")), Filename.length ()); inString absolutepath=F.getabsolutepath (); -String path=absolutepath.substring (0,absolutepath.lastindexof ("\ \") +1); toString Newname=path+system.currenttimemillis () + "" +suffix; +File newfile=NewFile (newname); - if(Newfile.exists ())//If there is already a file and the new file name in the directory, renaming is not allowed theSystem.out.println (newname+ "already exists! "); * Else{ $ F.renameto (newfile);Panax Notoginseng } - } the } + } A}
Re-encode the file to see another article. Http://www.cnblogs.com/zhangjinru123/p/7225775.html
The Java Traversal folder under the so file