I've asked a similar question in this link before but i still have this problem. This a code to explain my problem:
package main;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
public class MainClass {
public static void main(String[] args) throws IOException {
URL url = new URL("http://speedtest-ny.turnkeyinternet.net/100mb.bin");
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setReadTimeout(10000);
con.setConnectTimeout(10000);
con.connect();
InputStream inputStream = con.getInputStream();
int len;
byte[] buffer = new byte[1024];
while ((len = inputStream.read(buffer)) != -1) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("downlaoding : " + len);
}
System.out.println("finished");
}
}
if I disconnect my laptop from internet during download, download does not end and continues for a while(depending on the time i disconnect my laptop from internet). My questions are:
- why does this happen?
- how can I solve this problem?
Please help me. I really need your answer.
I apologize in advance if the grammar of my sentences is not correct. Because I can't speak English well.