Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Have you tried using Java NIO seen as you have Java 7 installed:</p> <pre><code>import java.io.FileOutputStream; import java.io.IOException; import java.net.URL; import java.nio.channels.Channels; import java.nio.channels.ReadableByteChannel; public class TestApp { public static void main(String[] args) { try { URL url = new URL("http://download.piriform.com/ccsetup320.exe"); ReadableByteChannel rbc = Channels.newChannel(url.openStream()); FileOutputStream fos = new FileOutputStream("c:/ccsetup320.exe"); fos.getChannel().transferFrom(rbc, 0, 1 &lt;&lt; 24); } catch (IOException ex) { ex.printStackTrace(); } } } </code></pre> <p>The above code is tested and works just fine, I got it from a similar question found <a href="https://stackoverflow.com/questions/921262/how-to-download-and-save-a-file-from-internet-using-java">here</a> we can see how the NIO makes coding so much easier :)</p> <p>EDIT:</p> <p>I have updated the code to use a swingworker and it downloads the file without a problem:</p> <pre><code>import java.io.FileOutputStream; import java.io.IOException; import java.net.URL; import java.nio.channels.Channels; import java.nio.channels.ReadableByteChannel; import javax.swing.SwingWorker; public class JavaApplication174 { public static void main(String[] args) { SwingWorker worker = new SwingWorker() { @Override protected Object doInBackground() throws Exception { try { URL google = new URL("http://download.piriform.com/ccsetup320.exe"); ReadableByteChannel rbc = Channels.newChannel(google.openStream()); FileOutputStream fos = new FileOutputStream("c:/ccsetup320.exe"); fos.getChannel().transferFrom(rbc, 0, 1 &lt;&lt; 24); } catch (IOException ex) { ex.printStackTrace(); } return this; } }; worker.run(); } } </code></pre> <p>EDIT 2:</p> <p>You call <code>execute()</code> on your workers instance use <code>run()</code> instead works for me!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload