• <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

        Android - Read Only File System IOException(Android - 只读文件系统 IOException)

                <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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How to send data to COM PORT using JAVA?(如何使用 JAVA 向 COM PORT 发送数据?)
                  How to make a report page direction to change to quot;rtlquot;?(如何使报表页面方向更改为“rtl?)
                  Use cyrillic .properties file in eclipse project(在 Eclipse 项目中使用西里尔文 .properties 文件)
                  Is there any way to detect an RTL language in Java?(有没有办法在 Java 中检测 RTL 语言?)
                  How to load resource bundle messages from DB in Java?(如何在 Java 中从 DB 加载资源包消息?)
                  How do I change the default locale settings in Java to make them consistent?(如何更改 Java 中的默认语言环境设置以使其保持一致?)
                  • <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>

                            <tbody id='M9dDR'></tbody>

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