【发布时间】:2013-01-28 08:58:14
【问题描述】:
我的应用程序中存在 SD 卡文件损坏问题(无论如何它只会打开文件以供读取)。它发生在一种特定情况下: - 应用程序一直在运行,并已从文件中加载数据(并再次关闭它) - 该应用程序没有被“强制关闭” - 手机以 SD 卡作为驱动器连接到 PC - 各种 PC 手机文件操作已进行(但此特定文件没有任何内容) - 手机与 PC 断开连接 - 下次运行应用程序时,文件将损坏,无法正确加载 - 损坏没有模式 - 随机垃圾 - 但文件长度永远不会改变
读取文件的代码如下,请注意 - 大大简化,各种尝试/捕获/其他测试以检查沿途的问题,并且工作正常,除了上面详述的。该文件是原始二进制文件,而不是文本。
String fullPath = " ... this will have the path to the file in it ... ";
FileInputStream
fs = new FileInputStream(fullPath);
DataInputStream
ds = new DataInputStream(fs);
Boolean res = loadBEBin(ds); // this reads and loads the file
fs.close();
return res;
困惑,感谢任何帮助。
【问题讨论】:
标签: android file-io android-sdcard