Download and save a file using Java
<p>Let's say I have an URL, like something.domain/myfile.txt then I want to save this file, with that "Save File" dialog.</p>

<p>I tried my best to do it, but everytime I save the file using the dialog the file is not there.</p>

<p>An example or somewhere I can find information on this would help a lot!</p>

<pre><code>        URL website = null;
                try {
                    website = new URL(&lt;insert url here&gt;);
                } catch (MalformedURLException e) {
                    e.printStackTrace();
                }
                ReadableByteChannel rbc = null;
                try {
                    rbc = Channels.newChannel(website.openStream());
                } catch (IOException e2) {
                    e2.printStackTrace();
                }
                FileOutputStream fos = null;
                try {
                    fos = new FileOutputStream(new File("minecraft.jar"));
                } catch (FileNotFoundException e1) {
                    e1.printStackTrace();
                }
                try {
                    fos.getChannel().transferFrom(rbc, 0, 1 &lt;&lt; 24);
                } catch (IOException e) {
                    e.printStackTrace();
                }

                    JFileChooser fileChooser = new JFileChooser();
                    if (fileChooser.showSaveDialog(fileChooser) == JFileChooser.APPROVE_OPTION) {
                      File dir = fileChooser.getCurrentDirectory(); 
                      dir.mkdir();
                      //After this point is where I need help.
</code></pre>
