Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get file path of file from internal storage in android

Tags:

In our application we are storing pdf files into internal storage.Now i want to get its filepath and need to store into DB. Please tell me how to get its file path. below code:

public void storeIntoInternalMem(byte[] databytes, String name) {
        try
        {
            FileOutputStream fileOuputStream = openFileOutput(name, MODE_PRIVATE);
            fileOuputStream.write(databytes);
            fileOuputStream.close();

        } catch (IOException e)
        {
            e.printStackTrace();
        }

    }
like image 279
Aarushi Avatar asked Nov 29 '13 07:11

Aarushi


People also ask

What is the file path for internal storage Android?

Internal Storage(UT) location: /storage/sdcard0 . Note that /sdcard & /storage/emulated/0 also point to Internal Storage(UT).

How do I find my internal storage path?

With Google's Android 8.0 Oreo release, meanwhile, the file manager lives in Android's Downloads app. All you have to do is open that app and select the "Show internal storage" option in its menu to browse through your phone's full internal storage.


2 Answers

you can use Context.getFilesDir() method to get the path to the internal storage

Edit

when using this line FileOutputStream fileOuputStream = openFileOutput(name, MODE_PRIVATE); the internal storage path is obtained by the default implementation of the openFileOutput() method. A new file is created at that location with the specified name. Now when you want to get the path of the same file, you can use the getFilesDir() to get the absolute path to the directory where the file was created. You can do something like this :-

File file = new File(getFilesDir() + "/" + name);

like image 160
d3m0li5h3r Avatar answered Oct 12 '22 01:10

d3m0li5h3r


String dir = getFilesDir().getAbsolutePath();

like image 37
VikingGlen Avatar answered Oct 12 '22 00:10

VikingGlen