Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: File class theoretical question

  1. #1
    Junior Member
    Join Date
    Jun 2011
    Thanked 0 Times in 0 Posts

    Question File class theoretical question

    I've been learning java for few days, and I've created a simple code using File class, which returns array of files in specified directory. So I have a question: is there any easy way to return array of ALL files in whole directory, here's an example:
    in path c:/ProgramFiles/ there are:
    1) dir1 (which has)
    ..1) dir1.1
    ..2) dir2.2
    2) dir2
    3) dir3
    and so on.
    So is there any solution how to return all the files/directories (including subfiles and subdirectories)? I would appreciate any hints

  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Thanked 833 Times in 772 Posts
    Blog Entries

    Default Re: File class theoretical question

    Recursively traverse through the directory...in pseudocode:
    1. for each file:
        if directory:
            list files -> go to 1.
             add to list

Similar Threads

  1. class interfacing to new server question
    By akhalsa in forum Object Oriented Programming
    Replies: 1
    Last Post: February 3rd, 2011, 12:03 AM
  2. Replies: 5
    Last Post: November 13th, 2010, 01:53 PM
  3. Question concerning nextLine() method in Scanner Class
    By r_sardinas in forum Java SE APIs
    Replies: 2
    Last Post: October 20th, 2010, 08:35 PM
  4. .class to .exe question
    By james137 in forum Java Theory & Questions
    Replies: 1
    Last Post: November 3rd, 2009, 09:18 PM
  5. How to link two classes in java to use it method
    By Sterzerkmode in forum Object Oriented Programming
    Replies: 3
    Last Post: May 13th, 2009, 06:52 AM