tags:

views:

92

answers:

1

I've created a JFileChooser which I use to locate a directory for a file to be saved to.

saveChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
saveChooser.showSaveDialog(null);
String exportPath = saveChooser.getCurrentDirectory() + "\\exportedData.txt";
System.out.println(exportPath);

(I then use exportPath for my file writer)

When I choose C:\Users\'me'\Eclipse\workspace\'project'\files in the JFileChooser the output is C:\Users\'me'\Eclipse\workspace\'project'\exportedData.txt

I've tried saving to multiple locations. It seems like it always drops the last directory. However, when I select root C:\ it uses My Documents which is the default I suppose. I know this probably isn't the best way to save a file and opens up to a few bugs, sorry. (The file name and extension is set in code).

A: 

I would guess that you want saveChooser.getSelectedFile(), and that in this case the selected file is really a directory. Hope that's right, didn't test.

john personna
Thanks! Seems like you were right!
HelloWorld