简体   繁体   中英

how to search subfolders and files to get input form the user using java

how to search subfolders and files to get input form the user using java,

using listRoot method, but how to use with give a File class path

use recursion on the top directory.Some thing as shown below

            class Main{

            public static void showFiles(File[] files) {
                for (File file : files) {
                    if (file.isDirectory()) {
                        System.out.println("Folder is  " + file.getName());
                        showFiles(file.listFiles()); 
                    } else {
                        System.out.println("File is  " + file.getName());
                    }
                }

                public static void main(String[] args) {
                    File[] files = new File("your path").listFiles();
                    showFiles(files);
                }}
            }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM