Android --- 读写文本保存

/*****
            //********保存填写信息********
            FileOutputStream fos=null;
            String text ="Try to write here尝试写操作";

            try {
                fos=openFileOutput("memo123_xiong",MODE_PRIVATE);//获得文件输出流对象
                fos.write(text.getBytes());//save info
                fos.flush();//clear buffer

            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }finally {
                if (fos!=null) {
                    try {
                        fos.close();
                        toast("保存成功!");
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }

        //****************读取保存的文件信息*****************
            byte [] buffer123={0};
            FileInputStream fis=null;
            try {
                fis =openFileInput("memo123_xiong");
                buffer123 =new byte[fis.available()];
                 fis.read(buffer123);
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }finally {
                if(fis!=null) {
                    try {
                        fis.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
                String data = new String(buffer123);
                tv_Receive.setText(data);
            }

         ***/

猜你喜欢

转载自blog.csdn.net/jobfind/article/details/82148972