问题
I have encountered a very strange problem in android:
In my app, i will upload files from cache directory. If a user uses cleaner app like cleanmaster to clear my app's cache directory while my app uploading files, all files got deleted, but the uploading tasks don't stop at all and will complete successfully later without losing any data. Moreover, while these "no source file task" still uploading, i can not access the cache directory any more, e.g. if i want to create a new file in the cache directory, i get 'ebusy' error.
my app use FileInputStream to open, read data form file in the upload task like this:
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 has cached the file while opened by FileInputStream, how can i disable caching? What i want is: if file deleted, reading from stream throw error and my uploading task stop.
My questions:
- Why FileInputSream still can be read while source file deleted
- Why the cache diretory is locked, by who?
- Any solution to my case?
来源:https://stackoverflow.com/questions/24911259/fileinputstream-still-can-be-read-while-source-file-deleted