java获取文件夹下所有文件的名称
1 import java.io.File; 2 3 public class GetFoldFileNames { 4 5 /** 6 * 7 * @author zdz8207 8 */ 9 public static void main(String[] args) { 10 getFileName(); 11 } 12 13 public static void getFileName() { 14 String path = "G:/lxz/20130611"; // 路径 15 File f = new File(path); 16 if (!f.exists()) { 17 System.out.println(path + " not exists"); 18 return; 19 } 20 21 File fa[] = f.listFiles(); 22 for (int i = 0; i < fa.length; i++) { 23 File fs = fa[i]; 24 if (fs.isDirectory()) { 25 System.out.println(fs.getName() + " [目录]"); 26 } else { 27 System.out.println(fs.getName()); 28 } 29 } 30 } 31 }