我的应用程序将外部捕获的照片复制到内部存储器。后来或立即将文件上传到在线世界中的服务器。在某些情况下,要上载的文件不存在导致FileNotFoundException。 78%的病例发生在小米设备中。
这是因为任何内存更清洁的应用程序?或任何相关的许可? 即使是可能出现问题的指示性想法也将受到赞赏。
Non-fatal Exception: java.io.FileNotFoundException: Could not find file at path: /data/user/0/in.oku.brofirst/files/1497511679961.jpg
at in.oku.brofirst.services.uploadservice.core.UploadFile.<init>(SourceFile:37)
at awm.a(SourceFile:78)
at awm.a(SourceFile:145)
at awf.a(SourceFile:87)
at awf.a(SourceFile:116)
at in.oku.brofirst.services.uploadservice.util.NetworkChangeReceiver.onReceive(SourceFile:45)
at android.app.ActivityThread.handleReceiver(ActivityThread.java:2732)
at android.app.ActivityThread.access$1800(ActivityThread.java:153)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1428)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5438)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:738)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:628)
传输文件方法
public File transferFile(File file) {
FileOutputStream fos = null;
FileChannel inChannel = null;
FileChannel outChannel = null;
try {
File transferredFileTo = new File(file.getName());// have the original name as the name in internal memory
inChannel = new FileInputStream(file).getChannel();
fos = context.openFileOutput(transferredFileTo.getName(), MODE_PRIVATE);
outChannel = fos.getChannel();
inChannel.transferTo(0, inChannel.size(), outChannel);
return transferredFileTo;
} catch (FileNotFoundException e) {
e.printStackTrace();
Crashlytics.logException(e);
} catch (IOException e) {
e.printStackTrace();
Crashlytics.logException(e);
} finally {
try {
if (inChannel != null && fos != null) {
inChannel.close();
fos.close();
}
} catch (IOException e) {
e.printStackTrace();
Crashlytics.logException(e);
} finally {
//ultimately delete the file from gallery
deleteLatestFile();
deleteFileFromTempFolder(file);
}
}
return null;
}
Crashlytics