Io stream Creating a list of Java files

Source: Internet
Author: User

 PackageCom.yyq;/** Practice: * Store the absolute path of a Java file in a specified directory into a text file * * Idea 1. Recursively * 2 for the specified directory. Gets the path to all Java files in the recursive process * 3. Store these paths in the collection * 4. Set Data stored in a file *//Storage to hard disk, hard disk, data persistence, write to file, no try Catch*/ImportJava.io.*;ImportJava.util.*; Public classJavafilelist { Public Static voidMain (string[] args)throwsIOException {//TODO auto-generated Method StubFile dir =NewFile ("d:\\apache-tomcat-7.0.63-windows-x64"); List<file>list =NewArraylist<file>();        Filetolist (dir, list);        System.out.println (List.size ()); File F=NewFile ("Java.txt");            Listwritetofile (f,list); }     Public Static voidFiletolist (File dir,list<file>list) {file[] files=Dir.listfiles ();  for(File file:files) {if(File.isdirectory ()) {filetolist (file,list); }            Else{                if(File.getname (). EndsWith (". Java") {list.add (file); }            }        }    }     Public Static voidListwritetofile (File f,list<file>list)throwsioexception{bufferedwriter BUFW=NewBufferedWriter (NewFileWriter (F.getpath ()));  for(File file:list) {bufw.write (File.getabsolutepath ());            Bufw.newline ();        Bufw.flush (); }    }}

Io stream Creating a list of Java files

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.