public class Demo06File { public static void main(String[] args) { show01(); show02(); } private static void show02() { //File数组 File file=new File("F:\basic\untitled12\src\it\cast\day14"); File[] files = file.listFiles(); for (File f : files) { System.out.println(f); } } private static void show01(){ File file=new File("F:\basic\untitled12\src\it\cast\day14"); String[] list = file.list();//list数组 for (String filename:list){ System.out.println(filename); } } }
结果:
demo01
demo02
demo03
F:asicuntitled12srcitcastday14demo01
F:asicuntitled12srcitcastday14demo02
F:asicuntitled12srcitcastday14demo03