Android 写入具有错误权限的文件

标签 android android-file android-permissions

当我将文件写入 sdcard 时,它写入文件的权限为 -rw-rw---- 并且所有者为 root。我遵循了文件写入权限的 android 指南,但它没有说明以 root 身份写入文件。我需要能够使用 android 文件管理器打开此文件,但没有权限,因为我没有 root 权限。 这是输出文件的代码:

 File file = getExternalStorageDirectory();

 File sim = new File(file, "Driving Sim App/");
 sim.getParentFile().mkdirs();
 sim = new File(sim, name+".csv");

 try {
     BufferedWriter bor = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(sim)));
     bor.write("This is a test");
     bor.close();
 } catch (FileNotFoundException e) {
     e.printStackTrace();
     return;
 } catch (IOException e) {
     e.printStackTrace();
 }

我的 list 文件中也有这个:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

任何帮助将不胜感激,谢谢!

最佳答案

您可能想尝试: File file = Environment.getExternalStorageDirectory();

关于Android 写入具有错误权限的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28906277/

相关文章:

android - 在哪里写入文本文件以及如何为 SD 卡设置它

android - 未授予 Android 应用程序中的互联网权限

Android Splash 运行时权限不起作用

android - 如何从 MediaStore.File 和 MediaStore.File.FileColumn 获取数据

android - 我如何从内存中查询歌曲的uri

android - 用户更改从设置屏幕授予权限

java - 在 FragmentActivity 中初始化接口(interface)

android - 类型 'int' 不是类型 'double' 的子类型

android - ICS 中的 TYPE_SYSTEM_OVERLAY

android - 使用 Retrofit 将 JsonArray 转换为 Kotlin 数据类(预期为 BEGIN_OBJECT 但为 BEGIN_ARRAY)