想在我的EditText打开SD卡的.txt文件 [英] trying to open the sdcard's .txt file in my EditText

查看:257
本文介绍了想在我的EditText打开SD卡的.txt文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图打开SD卡的.txt文件我的的EditText 来改变它的文字和
通过按一下按钮,但它在正确的方式我。可能知道什么是实现我的目标,正确的方法不会保存更改?


解决方案

 试试这个..您必须在清单文件设置权限:<使用许可权的android:NAME =android.permission.WRITE_EXTERNAL_STORAG​​E/>
         文件f =新的文件(Environment.getExternalStorageDirectory()getAbsolutePath()+,其次是乌拉圭回合文件目录);         文件f =新的文件(Environment.getExternalStorageDirectory()getAbsolutePath()+sdcard.txt);          为(文件wavfile:f.listFiles())
         {
            。字符串str = wavfile.getName()的toString();
         StringBuffer的StringBuffer的=新的StringBuffer();
                        串aDataRow =;
                        串aBuffer =;
                        尝试{
                            myfile文件=新的文件(/ SD卡/+文件名);
                            FIN的FileInputStream =新的FileInputStream(MYFILE);
                            的BufferedReader myReader =新的BufferedReader(
                                    新的InputStreamReader(FIN));                            而((aDataRow = myReader.readLine())!= NULL){
                                aBuffer + = aDataRow +\\ n;
                            }
                            myReader.close();
        edtitext.setText(aBuffer.tostring());                        }赶上(IOException异常五){
                            e.printStackTrace();
                        }
                   Toast.makeText(getApplicationContext        (),aBuffer,Toast.LENGTH_LONG).show();                    }
        }
        再次btnclick你必须编写编辑字符串的权利..        使用这一个在该文件中写入..
        FileOutputStream中FOS;
                           尝试{
                               myfile文件=新的文件(/ SD卡/+ 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();
                           }赶上(FileNotFoundException异常五){e.printStackTrace();}
                           赶上(IOException异常五){e.printStackTrace();}                    }    谢谢...
    更detalis参考此链接    http://www.javatpoint.com/android-external-storage-example
    -------------------------------------------------- --------

I am trying to open the sdcard's .txt file in my EditText to change the text in it and save the changes using button click but its not going in right way .May I know what is the correct way to achieve my objective?

解决方案

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

这篇关于想在我的EditText打开SD卡的.txt文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆