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"来读取私有文件!

  • 相关阅读:
    寒假学习第六天
    寒假学习第五天
    寒假学习第四天
    spark生态体系了解学习(六)
    spark生态体系了解学习(五)
    spark生态体系了解学习(四)
    spark生态体系了解学习(三)
    spark生态体系了解学习(二)
    spark生态体系了解学习(一)
    共享
  • 原文地址:https://www.cnblogs.com/fly_binbin/p/2123271.html
Copyright © 2011-2022 走看看