-2

I want that when my dialog is opened, then directly go to Homegroup. Thanks.

JFileChooser fc = null;
try {
    fc = new JFileChooser();
    fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    fc.setCurrentDirectory(new File(new URI("file:C:\\" + "..\\Homegroup")));
    fc.showOpenDialog(parent);
    return fc.getSelectedFile().getAbsolutePath();
} catch (Exception e) {
    return null;
}

This code is not working as I want. Thank you very much...

Tamás Sengel
  • 55,884
  • 29
  • 169
  • 223
  • Please format your code properly it is really hard to read. Also give some more context to what you're doing. – Arno C Dec 28 '17 at 23:25
  • Why are you trying to use a uri? Just specify the file path – MadProgrammer Dec 28 '17 at 23:30
  • Exceptions tell you what went wrong and where. If you ignore it, how are you supposed to know what to do? *Always* show the stack trace of a caught exception (unless you plan to make it the [cause](https://docs.oracle.com/javase/9/docs/api/java/lang/Throwable.html#initCause-java.lang.Throwable-) of a different thrown exception). – VGR Dec 29 '17 at 01:34

1 Answers1

0

The problem is that you provide an invalid URI and thus get a URISyntaxException. Try something more clean and efficient that accesses an existing file, or learn URI syntax:

fc.setCurrentDirectory(new File(System.getProperty("user.home")));
Cardinal System
  • 2,749
  • 3
  • 21
  • 42