Skip to content Skip to sidebar Skip to footer

Android Getfiledir Vs Getdir

What is the basic difference between getDir and getFileDir in android? AFAIK both will get the internal storage for the application.My question is when should I use getFileDir? Tha

Solution 1:

According to documentation here and here

public File getFilesDir ()

Returns absolute path of directory on the filesystem where files created with openFileOutput(String, int) are stored.

The returned path may change over time if the calling app is moved to an adopted storage device, so only relative paths should be persisted. No additional permissions are required for the calling app to read or write files under the returned path.

Where as

public File getDir(String name, int mode)

It takes name of the directory to retrieve. This is a directory that is created as part of your application data and operating mode(of type int). Use 0 or MODE_PRIVATE for the default operation, MODE_WORLD_READABLE and MODE_WORLD_WRITEABLE to control permissions.

Retrieve, creating if needed, a new directory in which the application can place its own custom data files.

You can use the returned File object to create and access files in this directory. Note that files created through a File object will only be accessible by your own application; you can only set the mode of the entire directory, not of individual files.

Post a Comment for "Android Getfiledir Vs Getdir"