1. <small id='52lTW'></small><noframes id='52lTW'>

      <legend id='52lTW'><style id='52lTW'><dir id='52lTW'><q id='52lTW'></q></dir></style></legend>
      • <bdo id='52lTW'></bdo><ul id='52lTW'></ul>
      1. <tfoot id='52lTW'></tfoot>
      2. <i id='52lTW'><tr id='52lTW'><dt id='52lTW'><q id='52lTW'><span id='52lTW'><b id='52lTW'><form id='52lTW'><ins id='52lTW'></ins><ul id='52lTW'></ul><sub id='52lTW'></sub></form><legend id='52lTW'></legend><bdo id='52lTW'><pre id='52lTW'><center id='52lTW'></center></pre></bdo></b><th id='52lTW'></th></span></q></dt></tr></i><div id='52lTW'><tfoot id='52lTW'></tfoot><dl id='52lTW'><fieldset id='52lTW'></fieldset></dl></div>

        数据目录在Android中没有读/写权限

        时间:2023-08-29

        • <legend id='A9qpi'><style id='A9qpi'><dir id='A9qpi'><q id='A9qpi'></q></dir></style></legend>
          1. <small id='A9qpi'></small><noframes id='A9qpi'>

            <tfoot id='A9qpi'></tfoot>
              <tbody id='A9qpi'></tbody>
              <i id='A9qpi'><tr id='A9qpi'><dt id='A9qpi'><q id='A9qpi'><span id='A9qpi'><b id='A9qpi'><form id='A9qpi'><ins id='A9qpi'></ins><ul id='A9qpi'></ul><sub id='A9qpi'></sub></form><legend id='A9qpi'></legend><bdo id='A9qpi'><pre id='A9qpi'><center id='A9qpi'></center></pre></bdo></b><th id='A9qpi'></th></span></q></dt></tr></i><div id='A9qpi'><tfoot id='A9qpi'></tfoot><dl id='A9qpi'><fieldset id='A9qpi'></fieldset></dl></div>

                  <bdo id='A9qpi'></bdo><ul id='A9qpi'></ul>
                  本文介绍了数据目录在Android中没有读/写权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我使用的是 Android 1.5 我的数据目录没有读/写权限

                  I m using Android 1.5 my data directory doesn't have the read/write permissions

                  System.out.println("DAta can write??--->"+Environment.getDataDirectory().canWrite());
                  System.out.println("DAta can read??--->"+Environment.getDataDirectory().canRead());
                  

                  所以请建议我如何为数据目录提供权限.

                  So please suggest me how to provide permissions for the data directory.

                  我要做的是创建一个文件并在模拟器的数据存储中添加一些内容,如下所示

                  What I'm trying to do is to create a file and add some content to it in the Data storage of the emulator like as below

                  private void writeToSDCard() {
                          try {
                  
                              File lroot = Environment.getDataDirectory();
                  
                              if (lroot.canWrite()){
                                  File lfile = new File(lroot, "samplefile.txt");
                                  FileWriter lfilewriter = new FileWriter(lfile);
                                  BufferedWriter lout = new BufferedWriter(lfilewriter);
                                  lout.write("XXXXXXXXXXXXXXXXXX");
                                  lout.close();
                              }
                          } catch (IOException e) {
                              Log.e(m_cTAG, "Could not write file " + e.getMessage());
                          }
                      }
                  

                  推荐答案

                  您不应该查看数据目录.这是手机存储中的系统目录 - 通常是 /data - 您的应用程序永远不会有写入权限.

                  You shouldn't be looking at the Data Directory. This is a system directory in the phone's storage - usually /data - and your application will never have permission to write to it.

                  您的应用程序应该写入文件的目录由 返回Context.getFilesDir() 方法.它将类似于 /data/data/com.yourdomain.YourApp/files.

                  The directory your application should write files to is returned by the Context.getFilesDir() method. It will be something like /data/data/com.yourdomain.YourApp/files.

                  如果您想写入手机存储中的文件,请使用 Context.openFileOutput() 方法.

                  If you want to write to a file in the phone's storage use the Context.openFileOutput() method.

                  如果您想要 SDCard 的路径,请使用 Environment.getExternalStorageDirectory() 方法.要写入 SDCard,您需要通过将以下内容添加到您的 Manifest 来为您的应用程序授予适当的权限:

                  If you want the path to the SDCard then use Environment.getExternalStorageDirectory() method. To write to the SDCard you'll need to give your application the appropriate permissions by adding the following to your Manifest:

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

                  如果您要写入 SDCard,您还需要使用 getExternalStorageState() 方法检查其状态.

                  If you're going to write to the SDCard you'll also need to check its state with the getExternalStorageState() method.

                  如果您要存储与应用程序相关的小文件,那么这些文件可以进入手机的存储空间而不是 SD 卡,因此请使用 Context.openFileOutput()Context.openFileInput() 方法.

                  If you're storing small files to do with your application then these can go into the phone's storage and not the SD Card, so use the Context.openFileOutput() and Context.openFileInput() methods.

                  所以在您的代码中考虑如下内容:

                  So in your code consider something like:

                  OutputStream os = openFileOutput("samplefile.txt", MODE_PRIVATE);
                  BufferedWriter lout = new BufferedWriter(new OutputStreamWriter(os));
                  

                  这篇关于数据目录在Android中没有读/写权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何在模拟器中测试 BOOT_COMPLETED 广播接收器 下一篇:Android 模拟器 - 创建用户帐户时遇到问题

                  相关文章

                  最新文章

                • <legend id='R5hWA'><style id='R5hWA'><dir id='R5hWA'><q id='R5hWA'></q></dir></style></legend>

                    <i id='R5hWA'><tr id='R5hWA'><dt id='R5hWA'><q id='R5hWA'><span id='R5hWA'><b id='R5hWA'><form id='R5hWA'><ins id='R5hWA'></ins><ul id='R5hWA'></ul><sub id='R5hWA'></sub></form><legend id='R5hWA'></legend><bdo id='R5hWA'><pre id='R5hWA'><center id='R5hWA'></center></pre></bdo></b><th id='R5hWA'></th></span></q></dt></tr></i><div id='R5hWA'><tfoot id='R5hWA'></tfoot><dl id='R5hWA'><fieldset id='R5hWA'></fieldset></dl></div>
                    <tfoot id='R5hWA'></tfoot>

                      • <bdo id='R5hWA'></bdo><ul id='R5hWA'></ul>

                      <small id='R5hWA'></small><noframes id='R5hWA'>