Note that there are some explanatory texts on larger screens.

plurals
  1. POProblem when downloading a file
    text
    copied!<p>Here's the problem I'm facing : I try to download a file from a tomcat server using the following snipet of code </p> <pre><code>try { BufferedInputStream getit = new BufferedInputStream(new URL("http://192.168.2.180:8080/android.apk").openStream()); FileOutputStream saveit = new FileOutputStream(path); BufferedOutputStream bout = new BufferedOutputStream(saveit,1024); byte data[] = new byte[1024]; int readed = getit.read(data,0,1024); while(readed != -1) { bout.write(data,0,readed); readed = getit.read(data,0,1024); } bout.close(); getit.close(); saveit.close(); } catch(Exception e) { e.printStackTrace } </code></pre> <p>The above works just fine when I run it on the emulator , but when I try to test it on my device it doesn't do anything , and ~50 sec later it throws a "socket timeout"exception at the line</p> <pre><code> BufferedInputStream getit = new BufferedInputStream(new URL("http://192.168.2.180:8080/android.apk").openStream()); </code></pre> <p>What is this happening and how can I fix it ?</p> <p>here's the stacktrace</p> <pre><code>04-19 12:28:19.865: WARN/System.err(2962): java.net.SocketException: The operation timed out 04-19 12:28:19.865: WARN/System.err(2962): at org.apache.harmony.luni.platform.OSNetworkSystem.connectSocketImpl(Native Method) 04-19 12:28:19.865: WARN/System.err(2962): at org.apache.harmony.luni.platform.OSNetworkSystem.connect(OSNetworkSystem.java:125) 04-19 12:28:19.865: WARN/System.err(2962): at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:227) 04-19 12:28:19.865: WARN/System.err(2962): at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:521) 04-19 12:28:19.865: WARN/System.err(2962): at java.net.Socket.connect(Socket.java:1019) 04-19 12:28:19.865: WARN/System.err(2962): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.&lt;init&gt;(HttpConnection.java:67) 04-19 12:28:19.865: WARN/System.err(2962): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnectionManager$ConnectionPool.getHttpConnection(HttpConnectionManager.java:151) 04-19 12:28:19.865: WARN/System.err(2962): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnectionManager.getConnection(HttpConnectionManager.java:73) 04-19 12:28:19.865: WARN/System.err(2962): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection.getHTTPConnection(HttpURLConnection.java:826) 04-19 12:28:19.865: WARN/System.err(2962): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:812) 04-19 12:28:19.865: WARN/System.err(2962): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1054) 04-19 12:28:19.865: WARN/System.err(2962): at java.net.URL.openStream(URL.java:674) </code></pre>
 

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