When reading from a file, Java net. URL cache

It seems that Java is saving some kind of cache for URLs (& files)

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

Return to version 1 (as expected)

I changed the file content to "version 2" and called this code again I still get "version 1"

How do I clear this cache

Note: I found it only happens on Linux

Solution

Because the jar protocol is used in the URL, the connection is sun net. www.protocol. jar. An instance of jarurlconnection, which can be downloaded from sun net. www.protocol. jar. Benefit from caching implemented in jarfilefactory

The source code confirms that setusecache (false) on the urlconnection implementation will prevent the cache from being used

My assumption about the Linux / windows behavior difference: the shutdown event notification from the urljarfileclosecontroller interface is triggered faster on windows because it doesn't like to keep the file handle open for too long

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>