I’m using the following code to download a file off a webserver that I control
URL url = new URL("http://........");
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
connection.setDefaultUseCaches(false);
connection.setUseCaches(false);
connection.setRequestMethod("GET");
connection.setDoOutput("true");
connection.connect();
InputStream in = connection.getInputStream();
File dst = new File(".......");
FileOutputStream out = new FileOutputStream(dst);
byte[] buffer = new byte[1024];
int len = 0;
while ((len=in.read(buffer))>0) {
out.write(buffer,0,len);
}
connection.disconnect();
in.close();
out.close();
minus all the necessary try-catches. The above code works fine for downloading the file to my specific destination. It is however unable to download the latest version (e.g. if i change the file contents on the webserver)
it is as though the something is keeping some sort of cache of the file it downloaded before, and as long as the URL is the same as before, it sends back the same file. My data connection becomes active during the download so this might be the case at my service provider
what I need is some sort of way to force my code to proactively refresh the target file. I have found that the web-browser was able to do this. if I were to type in the link with the web-browser, and then subsequently run my code again, the latst version gets downloaded
Try to add a
?time=201211261200at the end of URL.