The Java Traversal folder under the so file

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.