File: Iterate through the files or folders under the folder

Source: Internet
Author: User
Tags readfile

In the project, it is sometimes necessary to get all the files or folders under the folder, as well as the corresponding last modified time. The following code implements the iteration to read the file under the specified path, and the modification time can be added to the LastModified () method by itself.

 Public  class Folder {     Public Static void Main(string[] args) {String path="f:/111";    ReadFile (path); }/** Iterate Read all sub files or folders under folder * @param path folder paths */     Public Static void ReadFile(String Path) {File file=NewFile (path); file[] templist = File.listfiles ();//templist.length Get the number of files or folders that are contained under a folder           if(templist.length>0){ for(File f:templist) {//If it is a file, print the file name directly                  if(F.isfile ())                  {System.out.println (F.getname ()); }if(F.isdirectory ())                     {System.out.println (F.getname ()); ReadFile (path+"/"+f.getname ()); }                 }             }    }}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

File: Iterate through the files or folders under the folder

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.