安卓 文件創造

private類型

  • 只能本應用進行讀寫, 其他應用不可以訪問
  • 採用覆蓋寫的方法
  • 舉例
    public void save(String filename,String content) throws IOException {
        FileOutputStream outputStream = context.openFileOutput(filename, context.MODE_PRIVATE);
        outputStream.write(content.getBytes());
        outputStream.close();
    }

append

  • 只能本應用進行讀寫, 其他應用不可以訪問
  • 採用追加模式寫
  • 代碼
public void saveAppend(String filename,String content) throws IOException {
        FileOutputStream outputStream = context.openFileOutput(filename, context.MODE_APPEND);
        outputStream.write(content.getBytes());
        outputStream.close();
    }

MODE_WORLD_WRITEABLE

  • 創造的文件可以被其他應用寫

allow all other applications to have write access to the created file.

MODE_WORLD_READABLE

  • 創造的文件可以被其他應用讀

allow all other applications to have read access to the created file.

參考鏈接

-API: http://www.android-doc.com/reference/android/content/Context.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章