absolute path to directory in the internal storage in android?

橙三吉。 提交于 2019-12-08 02:27:58

问题


I want to keep my app required files inside a directory under internal storage. in the previous stage i used externalStorageDirectory to store my data. now i am using the below code to refer my external directory

 Environment.getExternalStorageDirectory()+"/mydirectory"; 

I need an equivalant code to refer my directory in the internal directory, can anybody help me...thanks,

Solution:

getFilesDir()+"/mydirectory";

thanks for all of your suggestion and help.


回答1:


Use getFilesDir() for that.

From the docs:

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

No permissions are required to read or write to the returned path, since this path is internal storage.

To answer your comment, I'll quote the docs docs:

By default, files saved to the internal storage are private to your application and other applications cannot access them (nor can the user). When the user uninstalls your application, these files are removed.




回答2:


public  File createDir() {
         FIle DIR=null;
         if (android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED))
                DIR=new File(android.os.Environment.getExternalStorageDirectory()+DIRNAME);
            else
                DIR=context.getCacheDir();
            if(!DIR.exists())
                DIR.mkdirs();
            return DIR;  
    }

This one i m using in one of my application and which creates the directory in external if it is mounted or not exists it will create in internal storage




回答3:


You can use this:

File f = new File(Environment.getDataDirectory(), "subdir");


来源:https://stackoverflow.com/questions/25905649/absolute-path-to-directory-in-the-internal-storage-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!