zoukankan      html  css  js  c++  java
  • 读写内部存储的文件数据

        把  XXX.txt文件 写入/读取  在data/data/包  目录下面。

     1 /** 读写内部存储的文件数据 */
     2         findViewById(R.id.btnWrite).setOnClickListener(
     3                 new View.OnClickListener() {
     4                     @Override
     5                     public void onClick(View v) {
     6                         try {
     7                             FileOutputStream fas = openFileOutput("text",
     8                                     Context.MODE_PRIVATE);
     9                             OutputStreamWriter asw = new OutputStreamWriter(
    10                                     fas, "UTF-8");
    11                             asw.write(et.getText().toString());
    12                             asw.flush();
    13                             fas.flush();
    14                             asw.close();
    15                             fas.close();
    16                             Toast.makeText(getApplicationContext(), "写入完成。",
    17                                     Toast.LENGTH_SHORT).show();
    18                         } catch (FileNotFoundException e) {
    19                             e.printStackTrace();
    20                         } catch (UnsupportedEncodingException e) {
    21                             e.printStackTrace();
    22                         }
    23                     }
    24                 });
    25         findViewById(R.id.btnRead).setOnClickListener(
    26                 new View.OnClickListener() {
    27                     @Override
    28                     public void onClick(View v) {
    29                         try {
    30                             FileInputStream fis = openFileInput("text");
    31                             InputStreamReader is = new InputStreamReader(fis,
    32                                     "UTF-8");
    33                             char input[] = new char[fis.available()];
    34                             is.read(input);
    35                             is.close();
    36                             fis.close();
    37                             String readed = new String(input);
    38                             show.setText(readed);
    39                         } catch (FileNotFoundException e) {
    40                             e.printStackTrace();
    41                         } catch (IOException e) {
    42                             e.printStackTrace();
    43                         }
    44                     }
    45                 });
  • 相关阅读:
    JQuery实现页面跳转
    CSS中让背景图片居中且不平铺
    C#后台将string="23.00"转换成int类型
    BootStrap的一些基本语法
    CSS实现文字阴影的效果
    BootStrap自定义轮播图播放速度
    BootStrap 轮播插件(carousel)支持左右手势滑动的方法(三种)
    C#常用快捷键
    jQuery hover() 方法
    鼠标移动有尾巴
  • 原文地址:https://www.cnblogs.com/androidsj/p/3910418.html
Copyright © 2011-2022 走看看