prokopis
prokopis

Reputation: 575

File path in Java on Android

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?

Upvotes: 3

Views: 21571

Answers (1)

Last Warrior
Last Warrior

Reputation: 1307

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...

Upvotes: 6

Related Questions