Java Build File Tree __java

Source: Internet
Author: User

Write your own Java-like Linux tree command to generate file trees, directly on the code

Import java.io.*;

Import Java.util.Arrays;
 /** * Created by su123 on 2017/4/9. */public class FileIO {public static void main (string[] args) {File file = new file ("d:\\apache-tomcat-7.0
        .77-windows-x64 ");
        
	File Dest = new file ("Dco.txt");
      
        BufferedWriter out = null;
        
        out = new BufferedWriter (new OutputStreamWriter (New FileOutputStream (dest,true)));
        
    Listpath (file,out);
    static int indentlevel =-1;
        public static void Listpath (file Path,bufferedwriter out) {file files[];
        indentlevel++;
        Files = Path.listfiles ();

        Arrays.sort (files);
                try{for (int i = 0, n = files.length i < n; i++) {File file = Files[i];
                    if (File.isdirectory ()) {System.out.print ("|");
                    Out.write ("|"); for (int indent = 0; indent < indentlevel; indent++) {System.Out.print ("--");
                    Out.write ("--");
                        }else{for (int indent = 0; indent < indentlevel; indent++) {
                        System.out.print ("");
                    Out.write ("");
                    } System.out.print ("| |");
                Out.write ("| |");
                    } if (File.isdirectory ()) {System.out.println ("D:" +file.getname ());
                    Out.write ("D:" +file.getname ());
                Out.newline ();
                    else {System.out.println ("F:" +file.getname ());
                    Out.write ("F:" +file.getname ());
                Out.newline ();
                } if (Files[i].isdirectory ()) {Listpath (files[i],out);
        }}catch (IOException e) {e.printstacktrace ();
   } indentlevel--; }

} 


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.