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 / First Aid / June 2005

Tip: Looking for answers? Try searching our database.

File chooser question

Thread view: 
aeh - 24 Jun 2005 15:05 GMT
Hi,

I am trying to build a gui using java that allows the user to go thru
filechooser and pick any file(s) and/or directories. If a file or files
are chosen then the names of the files are appended to a list. If a
directory is chosen then the names of all the files in the directory
should be appended to the list.

I already have most of this code written up. However the code I have
does not distinguish between a file and a directory so it doesn't know
to open the directory. I was hoping there might be some built in
function that would determine this for me but I can't seem to find it.

I am still very new to Java and am trying to teach myself. Any help
would be appreciated.
Matt Humphrey - 24 Jun 2005 15:20 GMT
> Hi,
>
[quoted text clipped - 11 lines]
> I am still very new to Java and am trying to teach myself. Any help
> would be appreciated.

You will want to check out the File API.  Look for isDirectory ().

Cheers,
Matt Humphrey  matth@ivizNOSPAM.com  http://www.iviz.com/
Fahd Shariff - 27 Jun 2005 15:42 GMT
int returnVal = chooser.showOpenDialog(parent);
if(returnVal == JFileChooser.APPROVE_OPTION) {
   File[] files = chooser.getSelectedFiles() ;
   for(int i = 0 ; i < files.length ; i++){
       File f = files[i] ;
       if(f.isDirectory()){
           String[] filenames = f.list() ;
           //append to your list
       }
       else{
           //append f to your list
       }
   }
}

--
Fahd Shariff
http://www.fahdshariff.cjb.net
"Let the code do the talking... "


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.