简体   繁体   English

Android 是否将文件从 SD 卡缓存到内部 memory?

[英]Does Android cache files from SD card to internal memory?

Have a situation.有情况。

  1. MediaPlayer plays some file, in the end of the file it starts play next one. MediaPlayer播放一些文件,在文件末尾开始播放下一个文件。

  2. All files stored on SD card(not emulated, but physical)存储在 SD 卡上的所有文件(不是模拟的,而是物理的)

  3. Android KitKat 4.4.4(if it's important) Android KitKat 4.4.4(如果很重要)

So, when first file is done playing and second starts to play, I'm checking if previous file still exists(no matter why, it's just workaround some problem).所以,当第一个文件播放完毕并且第二个文件开始播放时,我正在检查以前的文件是否仍然存在(不管为什么,这只是解决一些问题)。 And If I've to remove USB physically, than do File.exist it returns true but file is already not there.如果我必须物理删除 USB ,则File.exist它返回true但文件已经不存在。 So it must be false.所以一定是假的。

So question is.所以问题是。 Does Android cache SD card files(recently read) to internal memory(some cache)? Android 是否将 SD 卡文件(最近读取)缓存到内存(一些缓存)? And if yes, how do I clear this cache, or remove something from it?如果是的话,我该如何清除这个缓存,或者从中删除一些东西?

PS Yes, File.exist checking goes after USB remove, in 2-3 seconds after. PS 是的, File.exist检查在 USB 删除之后进行,在 2-3 秒后。

No, Android doesn't cache files by default on internal memory.不,Android 默认情况下不会在内部 memory 上缓存文件。

You may have initialized your file before removing file so it return true on following code.您可能在删除文件之前已初始化文件,因此它在以下代码中返回 true。

  • What you need to do is run this code when you need at runtime .您需要做的是在运行时需要runtime此代码。 Hope it will fix your issue here.希望它能在这里解决您的问题。
File file = new File(filePath);

if(file.exists())      
//Do something
else
// Do something else.```

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM