I think that your problem is that you're not using the File
chosen by the user, but the varaible f
that correspond to the root folder for the JFileChooser
. You should probably do something like that in your code :
File choosenFile = chooser.getSelectedFile();
This will get the selected file of the JFileChooser
. It's been a while since I've worked with that class so you will probably need to read a bit of the documentation here.
After you have the selected file, you can parse the file, and instead of creating a new File
, you can re-use the file variable :
Document document = docBuilder.parse(choosenFile);
I don't know if this will solved the problem, comment if you need anymore help.