I have a
URL url = new URL("/path/to/file.txt");
URLConnection urlConnection = url.openConnection();
urlConnection.setUseCaches(false);
and I read the contents of the file on Linux, cache is still used and I am not getting the actual contents if I change the contents.
Why is this not working? Shouldn't cache false get the latest?
Related: java.net.URL cache when reading from files
EDIT
getBytes(urlConnection.getInputStream());
public static byte[] getBytes(InputStream inputStream) throws IOException {
try ( InputStream is = inputStream; ByteArrayOutputStream bos = new ByteArrayOutputStream(BUFFER) ) {
byte[] buffer = new byte[BUFFER];
int length;
while ( (length = is.read(buffer)) != -1 ) {
bos.write(buffer, 0, length);
}
return bos.toByteArray();
}
}