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

查看:4266
本文介绍了在Android GETDIR和getFilesDir之间的区别是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想保存的图片在我的应用程序的内部存储容量,使之私。所以,我做了一些研究,发现2种方式来获得该目录。

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.采用<一href="http://developer.android.com/reference/android/content/ContextWrapper.html#getDir%28java.lang.String,%20int%29">getDir

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

2.采用<一href="http://developer.android.com/reference/android/content/ContextWrapper.html#getFilesDir%28%29">getFilesDir

File dir = getFilesDir();

哪家最好?其中在内部存储返回的位置?

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

写入文件的方法取决于您得到您的目录的方式吗?我有点失落,因为有很多方法可以在Android中写入文件。

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.

推荐答案

getFilesDir()返回一个文件对象的目录是私有的,只有你的应用程序。当您使用 openFileOutput(字符串,INT),你写的数据直接存储在这个目录中,并没有任何其他应用程序进行访问。它拥有你的应用程序文件。

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()使您能够创建在内部存储器中,这也是由依赖于创建它的模式的其他应用程序访问任何文件或目录。 openFileOutput(字符串,INT)不会,它的输出工作,所以你将不得不使用写入和读取文件来处理该目录或文件的其他手段。这是更多地用于创建自定义的文件以外唯一的应用程序使用的文件。

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.

这篇关于在Android GETDIR和getFilesDir之间的区别是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆