1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Problem with Java swing directory chooser

Discussion in 'Programming' started by infyrahul, May 9, 2012.

  1. #1
    I have used swing directory chooser to select input directory for my application to process.
    But if I select a particular directory, for example..
    c:/Desktop/user/documents/myfolder

    filechooser.getcurrentDirectory() returns only "c:/Desktop/user/documents/".
    Why? Can anyone say why this is happening?
     
    infyrahul, May 9, 2012 IP
  2. e-abi

    e-abi Member

    Messages:
    122
    Likes Received:
    1
    Best Answers:
    3
    Trophy Points:
    38
    #2
    And what code are you using? fileChooser.getSelectedFile() or fileChooser.getCurrentDirectory(); You should use the first option.
     
    Last edited: May 9, 2012
    e-abi, May 9, 2012 IP
  3. e-abi

    e-abi Member

    Messages:
    122
    Likes Received:
    1
    Best Answers:
    3
    Trophy Points:
    38
    #3
    It returns the directory you are inside, not the selected file.
    Remember fileChooser.getSelectedFile() can be a directory as well.
    http://docs.oracle.com/javase/6/docs/api/java/io/File.html#isDirectory() - you should check the resulting file with this function, to determine, whether it is a directory or not.
     
    e-abi, May 10, 2012 IP