java.net.URL cache when reading from files

Viewed 5809

It seems like java is holding some kind of a cache to URL (& files). e.g. I have a file "resourcs.txt" in a jar file in my classpath. The content of this file is: "Version 1"

new java.io.BufferedReader (new java.io.InputStreamReader( new URL("jar", "", "file:test.jar!/resourcs.txt").openConnection().getInputStream())).readLine()

returns "Version 1" (as expected)

I change the file content to be "Version 2" and call again to this code. And I still get "Version 1"

How can I clear this "cache".

Notice: I found out it only happens on Linux.

5 Answers

If you are using some third party code this should work:

url.openConnection().setDefaultUseCaches(false);
Related