【发布时间】:2020-04-23 08:44:40
【问题描述】:
我有一个位图,我想将它保存到 app 文件夹中。我尝试使用这些代码:
ContextWrapper contextWrapper = new ContextWrapper(context.getApplicationContext());
File directory = contextWrapper.getDir("tabs", Context.MODE_PRIVATE);
if (!directory.exists())
directory.mkdir();
String fname = "Image.jpg";
File file = new File(directory, fname);
FileOutputStream fos = null;
try {
fos = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.JPEG, 50, fos);
fos.close();
} catch (Exception e) {
Log.e("SAVE_IMAGE", e.getMessage(), e);
}
现在,我有两个问题。
- 为什么会显示此警告以及如何解决?
'File.mkdir()' 的结果被忽略
- 在应用程序文件夹中创建了目录“app_tabs”,但未保存位图并且文件夹中没有照片。如何保存此位图?
【问题讨论】:
-
更好:
if (!directory.exists()) if (!directory.mkdir()){toast could not make directory... return;}. -
Why this warning show?哪个警告? -
@blackapps “File.mkdir()”的结果被忽略
-
如何检查文件是否存在?
-
被忽略了吗?你为什么要?忽略意味着代码写得不好。
标签: java android android-file