在Android GETDIR和getFilesDir之间的区别是什么?(What is the difference between getDir and getFilesDir on Androi

Question:


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 :

File dir = getDir(Environment.DIRECTORY_PICTURES, Context.MODE_PRIVATE);

2.With getFilesDir :

File dir = getFilesDir();

Which is best ? Which returns the location in Internal Storage ?

The way of writing files depends on the way you get your dir ? I am a bit lost since there are many ways to write files in Android.

 

Answer:


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.

总而言之,最大的区别就是是否支持共享这一点.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值