我有这段代码
File dir = new File(Environment.getExternalStorageDirectory() + "/" + "new_dir");
if (dir.mkdir()) {
txtView.setText(dir + " Directory created");
} else {
txtView.setText(dir + " Directory is not created");
}
我还添加了
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
但它总是在else中,并且永远不会创建目录:S:S
答案 0 :(得分:0)
尝试此代码
String newFolder = "/myFolder2";
String extStorageDirectory = Environment.getExternalStorageDirectory().toString();
File myNewFolder = new File(extStorageDirectory + newFolder);
(!myNewFolder.mkdir())
{
Log.e(TAG, "Create dir in sdcard failed");
return;
}
用户权限
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />