我有一个Android应用程序,计划从给定的URL下载图像。 我想创建一个以输入命名的目录,包含多个文件(.jpg)。 文件的URL取自ArrayList。
在添加文件之前,我想为我的应用程序创建一个基本目录,如下所示:
String file_path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/myApp";
File dir = new File(file_path);
if(!dir.exists())
dir.mkdirs();
Log.i("Test","Directory created: "+dir.exists());
File file = new File(dir, "test.jpg");
FileOutputStream fOut = new FileOutputStream(file);
// image is the Bitmap created from one URL
image.compress(Bitmap.CompressFormat.JPEG, 100, fOut);
fOut.flush();
fOut.close();
我还添加了对清单文件的权限:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<application [...]
我自己的日志给我输出&#34;目录创建:false&#34;,我收到以下错误:
/storage/emulated/0/myApp/test.jpg: open failed: ENOENT (No such file or directory)
除了权限之外,还有什么问题可以解决?我正在测试nexus 5,Android 6.0.1