zoukankan      html  css  js  c++  java
  • openFileOutput的几种文件模式

     1     /**
     2      * 保存文件
     3      * @param filename 文件名称
     4      * @param content 文件内容
     5      */
     6     public void save(String filename, String content) throws Exception {
     7         //私有操作模式:创建出来的文件只能被本应用访问,其它应用无法访问该文件,另外采用私有操作模式创建的文件,写入文件中的内容会覆盖原文件的内容
     8         FileOutputStream outStream = context.openFileOutput(filename, Context.MODE_PRIVATE);
     9         outStream.write(content.getBytes());
    10         outStream.close();
    11     }
    12     
    13     /**
    14      * 保存文件
    15      * @param filename 文件名称
    16      * @param content 文件内容
    17      */
    18     public void saveAppend(String filename, String content) throws Exception {//ctrl+shift+y / x
    19         //私有操作模式:创建出来的文件只能被本应用访问,其它应用无法访问该文件,另外采用私有操作模式创建的文件,写入文件中的内容会覆盖原文件的内容
    20         FileOutputStream outStream = context.openFileOutput(filename, Context.MODE_APPEND);
    21         outStream.write(content.getBytes());
    22         outStream.close();
    23     }
    24     
    25     /**
    26      * 保存文件
    27      * @param filename 文件名称
    28      * @param content 文件内容
    29      */
    30     public void saveReadable(String filename, String content) throws Exception {
    31         //私有操作模式:创建出来的文件只能被本应用访问,其它应用无法访问该文件,另外采用私有操作模式创建的文件,写入文件中的内容会覆盖原文件的内容
    32         FileOutputStream outStream = context.openFileOutput(filename, Context.MODE_WORLD_READABLE);
    33         outStream.write(content.getBytes());
    34         outStream.close();
    35     }
    36     
    37     /**
    38      * 保存文件
    39      * @param filename 文件名称
    40      * @param content 文件内容
    41      */
    42     public void saveWriteable(String filename, String content) throws Exception {
    43         //私有操作模式:创建出来的文件只能被本应用访问,其它应用无法访问该文件,另外采用私有操作模式创建的文件,写入文件中的内容会覆盖原文件的内容
    44         FileOutputStream outStream = context.openFileOutput(filename, Context.MODE_WORLD_WRITEABLE);
    45         outStream.write(content.getBytes());
    46         outStream.close();
    47     }
    48     
    49     /**
    50      * 保存文件
    51      * @param filename 文件名称
    52      * @param content 文件内容
    53      */
    54     public void saveRW(String filename, String content) throws Exception {
    55         //私有操作模式:创建出来的文件只能被本应用访问,其它应用无法访问该文件,另外采用私有操作模式创建的文件,写入文件中的内容会覆盖原文件的内容
    56         FileOutputStream outStream = context.openFileOutput(filename, Context.MODE_WORLD_WRITEABLE + Context.MODE_WORLD_READABLE);
    57         outStream.write(content.getBytes());
    58         outStream.close();
    59     }
  • 相关阅读:
    html5 iframe
    html input复选框的checked属性
    H5新特性 本地存储---cookie localStorage sessionStorage
    input获得焦点时,如何让外边框不变蓝
    为了防止页面重新自动加载,可以给a标签设置href="javascript:void(0);"
    函数内部声明变量的时候,一定要使用var命令。如果不用的话,你实际上声明了一个全局变量!闭包访问局部变量
    svg
    js面向对象编程
    图片压缩上传
    jQuery的deferred对象详解
  • 原文地址:https://www.cnblogs.com/zhangshan/p/4481525.html
Copyright © 2011-2022 走看看