Application does not download the latest version of the [Java] file

Okay, I've been trying to figure this out for hours and it's starting to kill me.

I wrote a primitive version of the checker for an application that I work on every time and for a while. It's just an easy project to enjoy.

Verifying the version was, however, a pain. It worked the first few times I tested it, but since then it returned the same value over and over again, even though the file it was reading was deleted. I can only assume that it was cached somewhere and caching a version type file destroys the point of its existence.

Here is the code I am using to check the version number from my site:

    public int VersionNumber = 2005001; //to be updated to 2999999 when building to distribute
    public static boolean CheckUpdate() throws Exception {
        int ver = Integer.parseInt(getText("http://www.fragbashers.net/smite/version.txt"));
        System.out.println(ver);

    if (ver > VersionNumber) {
        System.out.println("Current version lower than newest!");
        return true;
    } else {
        return false;
    }
}

public static String getText(String url) throws Exception {
    URL website = new URL(url);
    URLConnection connection = website.openConnection();
    BufferedReader in = new BufferedReader(
        new InputStreamReader(
            connection.getInputStream()));
    StringBuilder response = new StringBuilder();
    String inputLine;

    while ((inputLine = in.readLine()) != null) 
        response.append(inputLine);

    in.close();

    return response.toString();
}

      

I use

int ver = Integer.parseInt(getText("http://www.fragbashers.net/smite/version.txt"));
    URL newClient = new URL("http://www.fragbashers.net/smite/RGP_" + ver + ".jar");

      

and some JFileChooser code to download the new version. This is not a problem.

The file on my website contains a 7 digit long int (2999999) which is the newest version file. Eclipse is printing an old version (2005001).

Basically I need help figuring out why the file is being cached and how I can stop it from being cached so it always has the most recent version.

+3


source to share


1 answer


Use URLConnection.setUseCaches(boolean);

.



In your case it would be connection.setUseCaches(false);

+1


source







All Articles