zoukankan      html  css  js  c++  java
  • 安卓读写文件和路劲注意事项

    写文件:

    private void writeToLocal(String filesString,String content,int mode) {
    try {
    FileOutputStream fisStream=openFileOutput(filesString,mode);
    fisStream.write(content.getBytes());
    fisStream.flush();
    fisStream.close();
    } catch (Exception e) {
    // TODO: handle exception
    }
    }

    读文件:

    private boolean readFile(String string) {
    try {
    BufferedReader reader=new BufferedReader(new InputStreamReader(new FileInputStream(basicPaString+string)));
    String valueString= reader.readLine();
    return true;
    } catch (Exception e) {
    return false;
    }
    }

    路径注意问题:

    Environment.getExternalStorageDirectory()为sd卡路劲

    如果读写文件时直接写文件名,则相当于this.getFilesDir()+"/"+文件名。路径为/data/data/包名/files/文件名

    为了保护用户隐私,在读取和写入SD卡信息的时候,运行在4.0系统以上的系统需要增加SD卡的读取和写入权限。

    文件的读写权限请看下图

  • 相关阅读:
    c++ CPO ADL
    c++ intrusive
    c++边界检查
    C++仿函数
    C++ RefBase
    c++ vector容器的尺寸问题
    关于调用约定
    C++学习之字符串类、容器
    C++异常
    Git常用命令大全,迅速提升你的Git水平
  • 原文地址:https://www.cnblogs.com/zhoumingxiu/p/4639921.html
Copyright © 2011-2022 走看看