Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/198.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 试图打开SD卡';我的EditText中的s.txt文件_Android - Fatal编程技术网

Android 试图打开SD卡';我的EditText中的s.txt文件

Android 试图打开SD卡';我的EditText中的s.txt文件,android,Android,我试图在我的EditText中打开SD卡的.txt文件,以更改其中的文本并 使用单击按钮保存更改,但操作方式不正确。请问实现目标的正确方法是什么 一些制造商(主要是三星)只对安装在/storage/sdcard上的内部存储器授予写入权限 此外,您还应通过在清单中添加此权限,使您的应用程序能够写入外部存储: 首先尝试读取完整的文本文件,并将文本保存为字符串 你可以参考这个 读取完整的文本文件并获取字符串中的文本时,请通过将字符串设置为editText edtitext.setText(your s

我试图在我的
EditText
中打开SD卡的.txt文件,以更改其中的文本并 使用单击按钮保存更改,但操作方式不正确。请问实现目标的正确方法是什么

一些制造商(主要是三星)只对安装在
/storage/sdcard
上的内部存储器授予写入权限

此外,您还应通过在清单中添加此权限,使您的应用程序能够写入外部存储:

首先尝试读取完整的文本文件,并将文本保存为字符串

你可以参考这个

读取完整的文本文件并获取字符串中的文本时,请通过将字符串设置为editText

edtitext.setText(your string);
试试这个。。
您必须在清单文件中设置权限:
文件f=新文件(Environment.getExternalStorageDirectory().getAbsolutePath()+“后跟ur文件目录”);
文件f=新文件(Environment.getExternalStorageDirectory().getAbsolutePath()+“sdcard.txt”);
对于(文件wavfile:f.listFiles())
{
字符串str=wavfile.getName().toString();
StringBuffer StringBuffer=新的StringBuffer();
字符串aDataRow=“”;
字符串aBuffer=“”;
试试{
File myFile=新文件(“/sdcard/”+文件名);
FileInputStream fIn=新的FileInputStream(myFile);
BufferedReader myReader=新的BufferedReader(
新的InputStreamReader(fIn));
而((aDataRow=myReader.readLine())!=null){
aBuffer+=aDataRow+“\n”;
}  
myReader.close();
edtitext.setText(aBuffer.tostring());
}捕获(IOE){
e、 printStackTrace();
}  
Toast.makeText(getApplicationContext
(),aBuffer,Toast.LENGTH_LONG)show();
}       
}
再次单击“必须正确写入已编辑的字符串”。。
用这个来写那个文件。。
文件输出流;
试试{
File myFile=新文件(“/sdcard/”+sdcard.txt);
myFile.createNewFile();
FileOutputStream fOut=新
FileOutputStream(myFile);
OutputStreamWriter myOutWriter=新建
OutputStreamWriter(fOut);
myOutWriter.append(数据);
myOutWriter.close();
fOut.close();
Toast.makeText(getApplicationContext(),文件名+)
保存“,Toast.LENGTH_LONG).show();
}catch(FileNotFoundException e){e.printStackTrace();}
catch(IOE异常){e.printStackTrace();}
}   
非常感谢。
更多详情请参考此链接'
http://www.javatpoint.com/android-external-storage-example
----------------------------------------------------------

我是android新手。我试图通过开发者控制台学习,但没有得到任何关于在android应用程序中编辑文本文件的信息
            try this one..

you must set permission in the manifest file:

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


         File f = new File(Environment.getExternalStorageDirectory().getAbsolutePath()                          + "followed by ur file dir");

         File f = new File(Environment.getExternalStorageDirectory().getAbsolutePath()                          + "sdcard.txt");

          for (File wavfile : f.listFiles())
         {
            String str = wavfile.getName().toString();   
         StringBuffer stringBuffer = new StringBuffer();    
                        String aDataRow = "";  
                        String aBuffer = "";  
                        try {  
                            File myFile = new File("/sdcard/"+filename);  
                            FileInputStream fIn = new FileInputStream(myFile);  
                            BufferedReader myReader = new BufferedReader(  
                                    new InputStreamReader(fIn));  

                            while ((aDataRow = myReader.readLine()) != null) {  
                                aBuffer += aDataRow + "\n";  
                            }  
                            myReader.close();  
        edtitext.setText(aBuffer.tostring());

                        } catch (IOException e) {  
                            e.printStackTrace();  
                        }  
                   Toast.makeText(getApplicationContext  

        (),aBuffer,Toast.LENGTH_LONG).show();  

                    }       
        }
        again btnclick you have to write that edited string right..



        use this one for write in that file..
        FileOutputStream fos;  
                           try {  
                               File myFile = new File("/sdcard/"+sdcard.txt);  
                                myFile.createNewFile();  
                                FileOutputStream fOut = new   

        FileOutputStream(myFile);  
                                OutputStreamWriter myOutWriter = new   

        OutputStreamWriter(fOut);  
                                myOutWriter.append(data);  
                                myOutWriter.close();  
                                fOut.close();  

                    Toast.makeText(getApplicationContext(),filename + "   

        saved",Toast.LENGTH_LONG).show();  


                           } catch (FileNotFoundException e) {e.printStackTrace();}  
                           catch (IOException e) {e.printStackTrace();}  

                    }   

    thank you...


    more detalis ref this link'

    http://www.javatpoint.com/android-external-storage-example
    ----------------------------------------------------------