In android, I ran into a very strange problem:
In my application, I will upload files from the cache directory. If the user uses clean applications, such as cleanmaster, to clear the application cache directory during application loading, all files have been deleted, but the download tasks do not stop at all and will be completed successfully later without losing any data. Moreover, although these βno tasks with the source fileβ are still loading, I can no longer access the cache directory, for example. if I want to create a new file in the cache directory, I get an "ebusy" error.
my application uses FileInputStream to open, read the data form file in the download task as follows:
InputSream in = new FileInputStream(file); byte[] buffer = new byte[4 * 1024]; int bytes; while ((bytes = in.read(buffer)) != -1) { netOutputStream.write(buffer, 0, bytes); } in.close();
I assume the system cached the file when opening FileInputStream, how can I turn off caching? I want: if the file was deleted, read from the stream error and stop loading.
My questions:
- Why FileInputSream can still be read when deleting the original file.
- Why is the cache directory blocked by whom?
- Any solution for my case?
source share