Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

File path for android when using emulator

I am new to android. I am trying to download a file from server and save the file in a particular path. The application is working fine. However I am not able to find the path of the downloaded file. In the code I have given as

File output = new File("/data/data/com.test.firstApp/", fileName);

Where can i find the file on my system?

like image 713
arungiri_10 Avatar asked Dec 21 '25 23:12

arungiri_10


2 Answers

Don't use hard coded file paths. The framework will give you the base path of the area you want to save files to.

For the SD card, use Environment.getExternalStorageDirectory()

For local files, use Context.getFilesDir() (or Context.openFileOutput(String name, int mode), etc)

For local cache, use Context.getCacheDir()

like image 148
Rich Avatar answered Dec 24 '25 14:12

Rich


Adding to Rich's answer, in the likely event you will end up writing to external storage make sure to include this permission in the manifest:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
like image 40
falro Avatar answered Dec 24 '25 13:12

falro