zoukankan      html  css  js  c++  java
  • android 读写私有文件

    所谓私有文件,则是指程序自己能读取,而其它程序没有权限访问的文件,此文件保存在Data.app.程序包.file目录下面。

    其中写文件的方法比较简单:


     private void writeFile(String fileName, String info) {
      try {
       FileOutputStream fout = openFileOutput(fileName, MODE_PRIVATE);
       byte[] bytes = info.getBytes();
       fout.write(bytes);
       fout.close();
      } catch (Exception err) {

      }
     }

    这样可以完成对私有文件的写,在写私有文件时使用的是openFileOutput 这个文件。

    上面对私有文件进行了写入,下面对私有文件进行读:

    private String readFile(String fileName) {
      try {
       FileInputStream fin = openFileInput(fileName);
       int length = fin.available();// 获取文件长度
       byte[] bytes = new byte[length];
       fin.read(bytes);
       return EncodingUtils.getString(bytes, ENCODING);
      } catch (Exception err) {
       return "";
      }
     }
    使用"openFileInput"来读取私有文件!

  • 相关阅读:
    shape与reshape
    opencv4.5.0 +contrib编译流程
    人脸定位(haar特征)
    最近邻分类法
    人脸识别概述
    跟踪视频中的物体
    估算稠密光流
    resize函数
    swap函数
    hibernate的session执行增删改查方法的执行步骤
  • 原文地址:https://www.cnblogs.com/fly_binbin/p/2123271.html
Copyright © 2011-2022 走看看