The Artima Developer Community
Sponsored Link

Java Answers Forum
Reading files in a folder

1 reply on 1 page. Most recent reply: Apr 1, 2003 4:09 PM by Singh M.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
Bruce Jacobs

Posts: 4
Nickname: comet304
Registered: Apr, 2003

Reading files in a folder Posted: Apr 1, 2003 10:56 AM
Reply to this message Reply
Advertisement
I have a folder on my c drive with hundreds of files. I need some java code to read these files and process them. If someone could give me some example code that would be helpful Thanks!!


Singh M.

Posts: 154
Nickname: ms
Registered: Mar, 2002

Re: Reading files in a folder Posted: Apr 1, 2003 4:09 PM
Reply to this message Reply
    private void parseDirectory(String path) throws IOException {
        File fd = new File(path);
        String [] strFileNameList = fd.list();
        Arrays.sort(strFileNameList);
        
        if (strFileNameList != null){
            for(int i=0; i<strFileNameList.length; i++) {
                File fCurrent = new File(path+System.getProperty("file.separator")+strFileNameList[i]);
                String p = path + System.getProperty("file.separator") + fCurrent.getName();
                
                if (fCurrent.isDirectory() == true) {
                    System.out.println(fCurrent.getName());
                   
                    //uncomment this part if you want to recurse into subdirectories. 
                    //parseDirectory(child, p);
                    
                } else {
                    System.err.println(fCurrent.getName());
                     
                    }
                }
            }
        }
    }//parseDirectory

Flat View: This topic has 1 reply on 1 page
Topic: tomcat and mod_jk2 problems Previous Topic   Next Topic Topic: URGENT: Sessions in JSP

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use