Dud*_*ude 6 android android-networking android-file
有人知道Android上的ProcessKiller进程吗?看来它杀死了我的应用程序,因为它有一个打开的文件。当我将文件下载到 SD 卡,然后在下载过程中拔出卡时,就会发生这种情况。这就是 logcat 所说的。
E/ProcessKiller( 2447): Process com.example.myapp (24090) has open file /storage/sda1/MyRecordings/81321226.recording/downloading/00000149.ts
E/ProcessKiller( 2447): Process com.example.myapp (24090) has open file /storage/sda1/MyRecordings/81321226.recording/downloading/00000149.ts
E/ProcessKiller( 2447): Process com.example.myapp (24090) has open file /storage/sda1/MyRecordings/81321226.recording/downloading/00000149.ts
E/ProcessKiller( 2447): Process com.example.myapp (24090) has open file /storage/sda1/MyRecordings/81321226.recording/downloading/00000149.ts
E/ProcessKiller( 2447): Process com.example.myapp (24090) has open file /storage/sda1/MyRecordings/81321226.recording/downloading/00000149.ts
E/ProcessKiller( 2447): Process com.example.myapp (24090) has open file /storage/sda1/MyRecordings/81321226.recording/downloading/00000149.ts
E/ProcessKiller( 2447): Process com.example.myapp (24090) has open file /storage/sda1/MyRecordings/81321226.recording/downloading/00000149.ts
E/ProcessKiller( 2447): Process com.example.myapp (24090) has open file /storage/sda1/MyRecordings/81321226.recording/downloading/00000149.ts
Run Code Online (Sandbox Code Playgroud)
我无法正确关闭该文件,因为它是我下载的临时文件,当用户在下载过程中拔出 SD 卡时会发生这种情况。所以我无法再访问该文件,因此无法关闭 FileOutputStream。
这就是我在抛出 IOException 后尝试关闭文件的方法(它也会抛出错误)。“fos”是一个文件输出流:
finally
{
try
{
Log.d(TAG, "Closing output file stream for file " + currentSegmentFile.getName());
fos.flush();
fos.getFD().sync();
fos.close();
}
catch (IOException e1)
{
Log.d(TAG, "Error closing file " + e1.getLocalizedMessage());
throw e1;
}
}
Run Code Online (Sandbox Code Playgroud)
因此,由于我无法关闭该文件,并且很快 ProcessKiller 出现在 Logcat 中,然后应用程序崩溃,因此我认为 ProcessKiller 由于打开的文件而杀死了我的应用程序。但ProcessKiller是什么我找不到更多信息。或者我是否应该以另一种方式关闭输出流,我也不知道。
如果有人有建议,请分享。多谢!干杯