6

I need to present to the user or my application a dialogue in which that point to a particular file so naturally the easiest choice is to use a JFileChooser.

However the file that needs to be selected is on a Windows network drive/share but it is mapped to a drive on the host computer running my app. The network share IS password and JFileChooser does present the drive in its dialoge but it cannot browse the drive until I use another program e.g. Windows Explorer to view the network share where it will ask for the password.

Is it possible for the JFileChooser to request the user for a password? Does JFileChooser receive notification from the system that password/authentication is required? Using the Sun example here, it just fails silently which is NOT what I want to happen. I want the user to be prompted for a password. Can I do this?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
D-Dᴙum
  • 7,689
  • 8
  • 58
  • 97
  • 1
    If you don't find a solution in the standard file chooser, you might craft your own based around [FileBro](http://codereview.stackexchange.com/questions/4446/file-browser-gui). – Andrew Thompson Feb 18 '12 at 11:44
  • Thanks Andrew. I'll keep that in mind however I cam across the Java class FileSystemView and might see what I can do with this. – D-Dᴙum Feb 18 '12 at 11:51
  • The alternative (without browse button) would be to use drag-and-drop. That would be acceptable if there were some tree view to drop into (more than one choice to place the file). Did you try Java 7? – Joop Eggen Feb 18 '12 at 12:01
  • You might use the awt FileChooser. – Joop Eggen Feb 18 '12 at 12:06
  • Java 7 is probably out of the question due to the SDK available (I have not control over it) and drag-and-drop would work but would like to avoid it if possible. thanks for your comments though. – D-Dᴙum Feb 18 '12 at 12:07
  • You could try running `net use …`, as shown [here](http://stackoverflow.com/a/208877/230513), although I'd prefer `ProcessBuilder`. You'd also have to critically examine the security implications. – trashgod Feb 18 '12 at 16:34

1 Answers1

1

PasswordAuthentication may come in handy in this case.. Example can be found here

PhonicUK
  • 13,486
  • 4
  • 43
  • 62
twid
  • 6,368
  • 4
  • 32
  • 50