我想拍照并将其保存在外部存储设备中,但文件夹创建失败。 权限已设定。
File folder = new File(Environment.getExternalStorageDirectory() +
File.separator + "DCIM" + File.separator + "ScannerApp");
if(!folder.exists()){
folder.mkdirs();
}
请帮助:)
答案 0 :(得分:0)
使用以下代码初始化folder
值:
File folder = new File(Environment.getExternalStorageDirectory(), "DCIM" + File.separator + "ScannerApp");
或
File folder = new File(new File(Environment.getExternalStorageDirectory(), "DCIM"), "ScannerApp");
答案 1 :(得分:-1)
替换此
File folder = new File(Environment.getExternalStorageDirectory() +
File.separator + "DCIM" + File.separator + "ScannerApp");
if(!folder.exists()){
folder.mkdirs();
}
带
File folder = new File(Environment.getExternalStorageDirectory().getPath() +
File.separator + "DCIM" + File.separator + "ScannerApp");
if(!folder.exists()){
folder.mkdirs();
}
问题是您使用的Environment.getExternalStorageDirectory()
不会返回路径。使用Environment.getExternalStorageDirectory().getPath()
获取路径。
希望这有帮助。