FileInputStream still can be read while source file deleted

人走茶凉 提交于 2019-12-11 18:49:55

问题


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:

  1. Why FileInputSream still can be read while source file deleted
  2. Why the cache diretory is locked, by who?
  3. Any solution to my case?

来源:https://stackoverflow.com/questions/24911259/fileinputstream-still-can-be-read-while-source-file-deleted

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!