This article describes the method of simply listing all files in a folder in Java. Share it for your reference, as follows:
import Java.io.*;public class ListFiles { private static String s = ""; private static BufferedReader in = new BufferedReader( new InputStreamReader(System.in)); public static void main(String[] args) { try { s = in.readLine(); getFileList(s); in.close(); } catch (IOException e) { e.printStackTrace(); } } public static void getFileList(String directory) { File f = new File(directory); File[] files = f.listFiles(); for (int i = 0; i < files.length; i++) { if (files[i].isFile()) { System.out.println("File:" + files[i]); } else { System.out.println("Directory:" + files[i]); // System.out.println("Directory Absolute Address:" + files[i].getAbsolutePath()); getFileList(files[i].getAbsolutePath()); } } }}For more Java-related content, readers who are interested in this site can view the topics: "Java Data Structure and Algorithm Tutorial", "Summary of Java Operation DOM Node Tips", "Summary of Java File and Directory Operation Tips" and "Summary of Java Cache Operation Tips"
I hope this article will be helpful to everyone's Java programming.