进程终止后android下载的文件丢失
我下载了一个jpeg文件并将其写入SD卡,但在进程被终止后,该文件丢失。为什么? 我写的文件如下:进程终止后android下载的文件丢失,android,file,process,Android,File,Process,我下载了一个jpeg文件并将其写入SD卡,但在进程被终止后,该文件丢失。为什么? 我写的文件如下: fileOut = new FileOutputStream(file); int length = 8192; byte[] buffer = new byte[length]; while (-1 != (length = in.read(buffer))) { fileOut.write(buffer, 0, length); } fileOut.flush(); fileOut.c
fileOut = new FileOutputStream(file);
int length = 8192;
byte[] buffer = new byte[length];
while (-1 != (length = in.read(buffer))) {
fileOut.write(buffer, 0, length);
}
fileOut.flush();
fileOut.close();
这是代码出口:
System.exit(0);
首先,不要在Android上调用System.exit。第二,Android版本是什么?你是如何测试文件丢失的?android4.0,在adb shell中搜索文件,如下所示:busybox查找-名称文件名和如何关闭应用程序进程?不要!Android的一个基本原则是,除非系统需要它的资源,否则该进程将保留下来以供潜在的重用。作为开发人员,您通常不应该试图关闭流程。