Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / March 2007

Tip: Looking for answers? Try searching our database.

directory and folders

Thread view: 
polilop - 09 Mar 2007 13:19 GMT
I need to traverse through a directory,which inside has a directory and
files. I need to save the directory name and files which are inside, to an
array, something like
Array [dirName][fileName] so i can print them out later something like
dirName
   fileName
   fileName1
dirName1
   fileName
   fileName1.
(they will be hyperlinks to files)
I have solved the problem of goining into a directory and getting the files
and other directories with a recursive funcition. My problem is how to store
the directory and file names, especially into an array as i dont allways
know how big my array could be.
Thanks in advanced

my recursive function.

public void doTest9( String path)
   {

    String mainDir = path;

       File dir = new File(mainDir);

       File[] files = dir.listFiles();

       for(int i = 0; i < files.length ; i++)
       {
         if(files[i].isDirectory())
           {
           doTest9(path+"\\"+files[i].getName()+"\\");
           }
        }

}
Joshua Cranmer - 10 Mar 2007 01:30 GMT
> I need to traverse through a directory,which inside has a directory and
> files. I need to save the directory name and files which are inside, to an
[quoted text clipped - 11 lines]
> the directory and file names, especially into an array as i dont allways
> know how big my array could be.

ArrayList works fine.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.