安卓在共享空间中创建文件
代码/**
* 创建文件
*
* @Param name
* @return
*/
public String fileCj(String name) {
// 获取外部存储路径
// String path = Environment.getDownloadCacheDirectory().getAbsolutePath()+"/"+name;
// Log.e("路径",Environment.getExternalStorageDirectory()+"");
// Log.e("",Environment.getExternalStorageState().equals("mounted")+"");//查看外部存储是否存在
// String path = context.getExternalFilesDir(null)+ "//" + name;
File createFiles = new File(name);
try {
if (!createFiles.exists()) {
createFiles.createNewFile();
}
} catch (IOException e) {
Log.d("文件创建失败", "files err:" + e.getMessage());
}
return name;
}
报错
D/文件创建失败: files err:Operation not permitted
D/文件创建失败: files err:Operation not permitted
D/文件创建失败: files err:Operation not permitted
D/文件创建失败: files err:Operation not permitted
D/文件创建失败: files err:Operation not permitted
D/文件创建失败: files err:Operation not permitted
W/System.err: java.io.FileNotFoundException: /storage/emulated/0/Documents/gnss/2022-01-12-03:45:55/GNSS/location.txt: open failed: EPERM (Operation not permitted)
页:
[1]