这是我的代码:
File dir = new File(Environment.getExternalStorageDirectory(), "newDir");
if (!dir.exists()) {
System.out.println(dir.mkdirs());
}
它总是打印错误。
在我的AndroidManifest.xml中,我有以下一行:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
我还尝试了代码第一行的以下变体:
File dir = new File(Environment.getExternalStorageDirectory() + File.separator + "newDir");
File dir = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/newDir");
File dir = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/newDir/");
File dir = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "newDir");
File dir = new File(Environment.getExternalStorageDirectory() + "newDir");
File dir = new File(Environment.getExternalStorageDirectory().toString() + "/newDir");
没有任何作用。
编辑:设备操作系统版本为6.0.1(Nexus 9平板电脑)。