Hi This is not trouble of J2EE group. It belongs to Java Core group :D, but I have 2 comments
public static ArrayList<File> ListFile(File filepath) { //1. You need to initialize filelist variable ArrayList<File> fileList = new ArrayList<File>; File[] file = filepath.listFiles(); for (File f:file) { if(f.isFile()) fileList.add(f); if (f.isDirectory()) //2. You need ListFile result to fileList too. fileList.addAll(ListFile(f)); } return fileList; } ________________________________ From: java-ee-j2ee-programming-with-passion@googlegroups.com [mailto:java-ee-j2ee-programming-with-pass...@googlegroups.com] On Behalf Of fantasticfour Sent: Monday, July 20, 2009 11:24 PM To: java-ee-j2ee-programming-with-passion Subject: [java ee programming] Is there something wrong with my code? Hi,everyone,i have trouble with following code,which is for listing all file in a filepath public static ArrayList<File> ListFile(File filepath) { ArrayList<File> fileList = null; File[] file = filepath.listFiles(); for (File f:file) { if(f.isFile()) fileList.add(f); if (f.isDirectory()) ListFile(f); } return fileList; } Thanks ! ________________________________ 网易YEAH.NET免费邮箱:您的终身免费邮箱 <http://yeah.net> </span --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Java EE (J2EE) Programming with Passion!" group. To post to this group, send email to java-ee-j2ee-programming-with-passion@googlegroups.com To unsubscribe from this group, send email to java-ee-j2ee-programming-with-passion-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/java-ee-j2ee-programming-with-passion?hl=en?hl=en -~----------~----~----~----~------~----~------~--~---