package com.file; import java.io.File; public class FileDemo { public static void main(String args[]) throws Exception { File file = new File("D:" + File.separator + "1" + File.separator); list(file); } public static void list(File file) { if (file.isDirectory()) { File f[] = file.listFiles(); if (f != null) { for (int x = 0; x < f.length; x++) { list(f[x]); } } } else { System.out.println(file); } } }