I'm new to Java so please bear with me.
In my program, I want to give the user the ability to save a file to the directory of their choice. After doing a little research, I found this nifty class called JFileChooser. What I want to do is allow the user to go to their desired directory through the JFileChooser GUI, type a name for their file, and allow them to save their file to the desired directory. I tried looking online for a solution to how to do this but almost everywhere I read, the final answer was "Now you have to make your program save the file" which I have no idea how to do. Could someone provide some well commented dummy code that would do the above description? Also, does anyone know whether JFileChooser provides a "New Folder" option?
Thanks in advance.
It's not trivial to put all of the pieces together. You need a FileFilter to save to particular extensions.
Here's an example from one of my Swing applications.
You’ll notice that there’s code in the method to ensure that the EXTENSION is appended on the end of the file name, unless the EXTENSION already exists. This is standard Windows behavior that is missing in the Java equivalent.
In order to save a particular extension, you'll need a FileFilter.
And finally, the LayoutFileFilter.