Search code examples
jfilechooserunc

Set JFileChooser current dir to remote dir


I have to set current dir in JFileChooser to remote dir(windows share), but it doesn't work.

JFileChooser chooser = new JFileChooser();
chooser.setCurrentDirectory(new File("\\\\192.168.11.11"));
chooser.showSaveDialog(null);

I found this bug description: https://bugs.java.com/bugdatabase/view_bug;jsessionid=ad25b2513da86b421875051509357?bug_id=6741919, but it isn't fixed yet. Is it any way to work it around(I can't map that dir)?


Solution

  • If you set the file path in the constructor like so:

    fc=new JFileChooser("\\\\10.16.7.139\\ErrorLogs");
    

    it works fine, although it seems like you can't open the root of the server. If I removed the \ErrorLogs portion of the string it didn't work.