File path for android when using emulator

13,029

Solution 1

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()

Solution 2

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" />
Share:
13,029
arungiri_10
Author by

arungiri_10

Having 7+ year of experience, at present working as a Senior Software Developer, major working domain are Design, Program and Developing of Android and Java Projects. Summary of Technical and Personal Skills. Worked on the mobile operating systems which include Android Worked on java core, JSON, RxJava and RxAndroid, GSON, GIT, Retrofit, MVP Design pattern. Ability to develop unique, cutting edge applications for different handset and user requirements In-depth knowledge of industry practices and application development protocols Knowledge of application testing, debugging and troubleshooting Ability to work for long hours without losing patience and enthusiasm Passionate to update my knowledge and skills though continuous self learning

Updated on June 08, 2022

Comments

  • arungiri_10
    arungiri_10 almost 2 years

    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?

  • arungiri_10
    arungiri_10 almost 12 years
    I agree to u and I used the getFilesDir(). The app worked fine even now. My question is - My android emulator downloaded file from server and stored at getFilesDir() path. Where is this path on my computer? I want to open the file that I have downloaded in a notepad.
  • Rich
    Rich almost 12 years
    getFilesDir returns a File object. On this File object, log the String value of File.getAbsoluteFilePath, and that will tell you the full absolute path to the root directory.
  • arungiri_10
    arungiri_10 almost 12 years
    I got the path in this form: /data/data/com.test.firstApp/files/test_123.wav. So where will I find it on my system?
  • Rich
    Rich almost 12 years
    Not sure what "on my system" means. The emulator uses a virtual storage that isn't directly mapped to a folder on your computer's hard drive. To get at that file, open up an "adb shell" session at the command line. You can browse the emulator's virtual storage using the usual unix/linux commands (cd, ls, ...), and you can copy it onto your computer's local storage using "adb pull" command
  • arungiri_10
    arungiri_10 almost 12 years
    Brilliant dude. Thank you soooooooo much. This is what I was searching for. I found the file. :)