File path in Java on Android

21,410

Import your test.txt file in the directory

/mnt/sdcard/

and access it

String youFilePath = Environment.getExternalStorageDirectory().toString()+"/test.txt"
File file=new File(youFilePath);

Hope this will work in your case...

Share:
21,410
prokopis
Author by

prokopis

Updated on November 24, 2020

Comments

  • prokopis
    prokopis over 3 years

    When I upload my program to my Android device, it will have a text file on the device. I have created it in the package directory, and I suppose that it will be uploaded to the device when I deploy the package.

    How can I find the file path of the text file in order to be able to use it from the application, so I can read from the file?

    I tried some simple code: File file=new File("test.txt");

    Is this possible and if so, how can it be done?