Results 1 to 9 of 9
  1. #1
    ANSHUMAN is offline Member
    Join Date
    Jun 2010
    Location
    Gujarat, India
    Posts
    2
    Rep Power
    0

    Default How to retrieve a path from a filechooser?

    Hey I am very very new to Java. I hope someone can help me with this -
    I want the user to select a directory using the filechooser. The problem is, I want the user selected directory's path. i want to be able to retrieve this path, so that i can feed it to my dropdown box whose options should be dynamically created by listing the files under that selected directory.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,250
    Rep Power
    19

    Default

    Read the API for JFileChooser and follow the link to the tutorial on How to Use File Choosers.

    Then read the API for java.io.File. Note that a folder is also a File.

    Come back when you have a question that's specific enough for someone to actually attempt to answer.

    db

  3. #3
    ANSHUMAN is offline Member
    Join Date
    Jun 2010
    Location
    Gujarat, India
    Posts
    2
    Rep Power
    0

    Default

    I have gone through the tutorials before I posted here, let me clarify my problem, I will break it down into parts:

    I used a file chooser that will allow the user to choose a directory. so far so good.
    Now I want the full path to that directory, because I will be using this path for further use in my program.

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,250
    Rep Power
    19

    Default

    Quote Originally Posted by ANSHUMAN View Post
    Now I want the full path to that directory
    I already told you to read the API for java.io.File. What didn't you understand in what you read?

    db

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  7. #7
    j2me64's Avatar
    j2me64 is offline Senior Member
    Join Date
    Sep 2009
    Location
    Zurich, Switzerland
    Posts
    962
    Rep Power
    6

    Default

    Quote Originally Posted by ANSHUMAN View Post
    I have gone through the tutorials before I posted here, let me clarify my problem, I will break it down into parts:

    I used a file chooser that will allow the user to choose a directory. so far so good.
    Now I want the full path to that directory, because I will be using this path for further use in my program.

    ok, the use File.getParent from the Class File and you will get the path of the file.

  8. #8
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,250
    Rep Power
    19

    Default

    Quote Originally Posted by j2me64 View Post
    ok, the use File.getParent from the Class File and you will get the path of the file.
    Whay would anyone wanting the full path use getParent()? Looks like you didn't read the API either.

    db

    edit Or maybe you didn't read the question. The file chooser is being used to select a directory, not a "file in a directory"
    Last edited by DarrylBurke; 06-06-2010 at 02:09 PM.

  9. #9
    j2me64's Avatar
    j2me64 is offline Senior Member
    Join Date
    Sep 2009
    Location
    Zurich, Switzerland
    Posts
    962
    Rep Power
    6

    Default

    Quote Originally Posted by Darryl.Burke View Post
    Whay would anyone wanting the full path use getParent()? Looks like you didn't read the API either.

    i know the API, so if you want to read only directories use

    Java Code:
    fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    Quote Originally Posted by Darryl.Burke View Post
    The file chooser is being used to select a directory, not a "file in a directory"
    The default mode in the file chooser is FILES_ONLY.
    Last edited by j2me64; 06-07-2010 at 09:49 AM.

Similar Threads

  1. FileChooser
    By Unsub in forum New To Java
    Replies: 7
    Last Post: 03-10-2010, 03:54 AM
  2. setting class-path & Library Path in ubantu
    By programmer_007 in forum Eclipse
    Replies: 18
    Last Post: 02-22-2010, 12:31 PM
  3. FileChooser
    By jperson in forum New To Java
    Replies: 2
    Last Post: 01-23-2010, 04:43 PM
  4. Filechooser
    By Joe2003 in forum New To Java
    Replies: 5
    Last Post: 02-26-2009, 07:51 AM
  5. FileChooser UI
    By heartysnowy in forum New To Java
    Replies: 5
    Last Post: 11-27-2008, 03:31 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •