Java basic file and recursive exercises use the filter filters to get and print small files smaller than 200K under the specified folder to print hierarchically (including files for all subfolders)

Source: Internet
Author: User

 PackageCom.swift.kuozhan;ImportJava.io.File;ImportJava.io.FileFilter;/*Use the file filter filter to get and print small files smaller than 200K under the specified folder (including files for all subfolders). */ Public classKuaozhan1 { Public Static voidMain (string[] args) {File dir=NewFile ("c:/"); if(!dir.exists ()) {            Throw NewRuntimeException ("This folder does not exist"); } get200 (dir,0); }    Private Static voidget200 (File dir,intlength) {        if(!dir.exists ()) {            Throw NewRuntimeException ("This folder does not have access rights"); }         for(inti = 0; i < length; i++) System.out.print ("\ T");        System.out.println (dir); file[] Files= Dir.listfiles (NewFileFilter () {@Override Public BooleanAccept (File pathname) {if(Pathname.isdirectory ())return true; if(Pathname.ishidden ())return false; if(Pathname.length ()/1024x768 < 200)                    return true; return false;        }        });  for(File file:files) {if(File.isdirectory ()) {get200 (file, length+ 1); } Else {                 for(inti = 0; i < length; i++) System.out.print ("\ T"); System.out.println ("\ T" +file); }        }    }}

Java basic file and recursive exercises use the filter filters to get and print small files smaller than 200K under the specified folder to print hierarchically (including files for all subfolders)

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.