I have a code like this
public void downloadZip(String URL, String fileName) {
try {
java.net.URL url = new URL(URL);
URLConnection conn = url.openConnection();
InputStream in = conn.getInputStream();
FileOutputStream out = new FileOutputStream(save + "/" + fileName);
byte[] b = new byte[4096];
int count;
while ((count = in.read(b)) >= 0) {
out.write(b, 0, count);
}
out.flush(); out.close(); in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
How can I rewrite it to be able to continue/stop loading?
You need to use a separate thread using SwingUtilities. In the GUI thread you set a flag if you want to stop. If you want to resume, you can reopen the URL and use the skip method of the InputStream to start from where you left. To pause, resume you can use signals. See http://tutorials.jenkov.com/java-concurrency/thread-signaling.html.
You need to educate yourself about multi-threading.