zoukankan      html  css  js  c++  java
  • 【安卓8】文件的读写

          Android的I/O方法

    方法

    描述

    public FileInputStream openFileInput(String name)

    设置要打开的文件输入流

    public FileOutputStream openFileOutput(

          String name,int mode)

    设置要打开的文件输出流,指定操作模式,可以是0、MODE_APPEND、MODE_PRIVATE、MODE_WORLD_READABLE、MODE_WORLD_WRITEABLE

    public Resources getResources()

    返回Resources对象

     

     

     

     

     

     

     

    文件的读写权限

        openFileOutPut(String fliename,int model)

      存储数据至指定文件名,第二个参数是文件的操作模式,有以下四个常量值:

    •   MODE_PRIVATE:设置文件属性为私有,只能被当前项目读写
    •   MODE_APPEND:以添加方式打开文件,并向文件中添加数据
    •   MODE_WORLD_READABLE:该文件可被其他项目读取
    •   MODE_WORLD_WRITEABLE: 该文件可被其他项目写入

      

     保存(写入)文件的操作

    //读取文件的操作
    FileOutputStream fos=null;
        try {
            fos=openFileOutput("test.txt", Activity.MODE_PRIVATE);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    PrintWriter out=new PrintWriter(fos);
    out.print("白日依山尽");
    out.print("黄河入海流");
    out.close();
    保存文件的操作

       

      读取文件的操作

    //读取文件的操作
    try {
        FileInputStream fis=openFileInput("test.txt");
        BufferedReader br=new BufferedReader(new InputStreamReader(fis));
        String str=null;
        while((str=br.readLine())!=null){
            TextView tv=(TextView) findViewById(R.id.TV);
            tv.setText(str);    }
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    读取文件的操作
  • 相关阅读:
    构建之法作业要求 20160922
    构建之法作业截止 20160908
    作业成绩 20160901
    动态范围理解
    解像力理解以及单位换算;
    QT:基本知识(一);
    qml: 截图(单窗口);
    (转载)python: getopt的使用;
    python: with的使用;
    qml: 自定义输入框
  • 原文地址:https://www.cnblogs.com/leelee/p/6994707.html
Copyright © 2011-2022 走看看