0

I want to use the JFileChooser in Java to get the user to select where they would like to save a file. I have used this code:

JFileChooser chooser = new JFileChooser();
        chooser.showOpenDialog(null);
        File f = chooser.getSelectedFile();
        String filename = f.getAbsolutePath();

This works and does get the path however the dialog box requires the user to select a file in order to get the file path. As i want it to save a new file i need it to get the path without having to select a file but from the folder the user has selected instead.

Im new to this and not sure of any other way of doing this, please could you advise me on a way around this.

1 Answer 1

6

chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.