What is the difference between getDir and getFilesDir on Android?

后端 未结 1 1028
自闭症患者
自闭症患者 2020-12-13 13:22

I would like to save a picture in Internal Storage of my app, to make it private. So I did a little research and saw 2 ways to get the directory.

1.With getDir :

相关标签:
1条回答
  • 2020-12-13 13:26

    getFilesDir() returns a File object to a directory that is private to your application only. When you use openFileOutput(String, int), the data you write is directly stored in this directory and is not accessible by any other application. It holds your application files.

    getDir() enables you to create any file or directory in the internal memory, which is also accessible by other applications depending on the mode you create it. openFileOutput(String, int) will not work with the output of this so you will have to use other means of writing and reading files to deal with this directory or file. This is more used for creating custom files other than files only used by your application.

    0 讨论(0)
提交回复
热议问题