• <tfoot id='oFQb4'></tfoot>

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

          <bdo id='oFQb4'></bdo><ul id='oFQb4'></ul>

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

        Android - 只读文件系统 IOException

        时间:2023-06-26

                <bdo id='Tggjm'></bdo><ul id='Tggjm'></ul>

                  <tbody id='Tggjm'></tbody>

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

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

                  <tfoot id='Tggjm'></tfoot>
                  本文介绍了Android - 只读文件系统 IOException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试在 Android 系统上写入一个简单的文本文件.这是我的代码:

                  I am trying to write to a simple text file on the Android system. This is my code:

                  public void writeClassName() throws IOException{
                      String FILENAME = "classNames";
                      EditText editText = (EditText) findViewById(R.id.className);
                      String className = editText.getText().toString();
                  
                      File logFile = new File("classNames.txt");
                         if (!logFile.exists())
                         {
                            try
                            {
                               logFile.createNewFile();
                            } 
                            catch (IOException e)
                            {
                               // TODO Auto-generated catch block
                               e.printStackTrace();
                            }
                         }
                         try
                         {
                            //BufferedWriter for performance, true to set append to file flag
                            BufferedWriter buf = new BufferedWriter(new FileWriter(logFile, true)); 
                            buf.append(className);
                            buf.newLine();
                            buf.close();
                         }
                         catch (IOException e)
                         {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                         }
                  

                  但是,此代码会产生java.io.IOException:打开失败:EROFS(只读文件系统)"错误.我尝试按如下方式向我的清单文件添加权限,但没有成功:

                  However, this code produces a "java.io.IOException: open failed: EROFS (Read-only file system)" error. I have tried adding permissions to my Manifest file as follows with no success:

                  <?xml version="1.0" encoding="utf-8"?>
                  <manifest xmlns:android="http://schemas.android.com/apk/res/android"
                  package="hellolistview.com"
                  android:versionCode="1"
                  android:versionName="1.0" >
                  
                  <uses-sdk android:minSdkVersion="15" />
                  
                  <application
                      android:icon="@drawable/ic_launcher"
                      android:label="@string/app_name" >
                      <activity
                          android:name=".ClassView"
                          android:label="@string/app_name" >
                          <intent-filter>
                              <action android:name="android.intent.action.MAIN" />
                  
                              <category android:name="android.intent.category.LAUNCHER" />
                          </intent-filter>
                      </activity>
                  
                       <activity 
                          android:name=".AddNewClassView" 
                          />
                  
                  </application>
                  <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
                  

                  有谁知道问题出在哪里?

                  Anyone have any idea what the problem is?

                  推荐答案

                  因为你正在尝试将文件写入root,所以你需要将文件路径传递给你的文件目录.

                  Because you are trying to write the file to root, you need to pass the file path to your file directory.

                  例子

                  String filePath = context.getFilesDir().getPath().toString() + "/fileName.txt";
                  File f = new File(filePath);
                  

                  这篇关于Android - 只读文件系统 IOException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:Android Emulator 无法启动,因为文件夹错误 下一篇:这 4 行 java 代码在 android 应用程序中意味着什么?

                  相关文章

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

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

                    <legend id='M9dDR'><style id='M9dDR'><dir id='M9dDR'><q id='M9dDR'></q></dir></style></legend>

                        <bdo id='M9dDR'></bdo><ul id='M9dDR'></ul>