Java basic File and recursive exercises use a File filter to filter small files smaller than kb in a specified folder and print them in a hierarchical manner (including all subfolders ),

Source: Internet
Author: User

Java basic File and recursive exercises use a File filter to filter small files smaller than kb in a specified folder and print them in a hierarchical manner (including all subfolders ),

Package com. swift. kuozhan; import java. io. file; import java. io. fileFilter;/* use the File filter to filter and obtain and print small files smaller than kb in the specified folder (including files in all subfolders ). */Public class kuaozhan1 {public static void main (String [] args) {File dir = new File ("c:/"); if (! Dir. exists () {throw new RuntimeException ("this folder does not exist");} get200 (dir, 0);} private static void get200 (File dir, int length) {if (! Dir. exists () {throw new RuntimeException ("this folder has no access permission") ;}for (int I = 0; I <length; I ++) System. out. print ("\ t"); System. out. println (dir); File [] files = dir. listFiles (new FileFilter () {@ Override public boolean accept (File pathname) {if (pathname. isDirectory () return true; if (pathname. isHidden () return false; if (pathname. length ()/1024 <200) return true; return false ;}}); for (File file: files) {if (file. isDirectory () {get200 (file, length + 1);} else {for (int I = 0; I <length; I ++) System. out. print ("\ t"); System. out. println ("\ t" + file );}}}}

 

Related Article

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.