10

I have a file named abikor.txt inside the files directory in the private app folder:

/data/data/myapp/files/abikor.txt

How can I get the path of this file?

I have seen the following questions but they don't address my problem.

(In general, how to get the path of a file stored under /files directory in the private app directory?)

Kind Regards

1 Answer 1

16

For the Internal Storage path you need to specify some thing like this

String path = context.getFilesDir().getAbsolutePath();

Then create a file object from the path

File file = new File(path + "/abikor.txt");

and if you want to Read the file from it then

int length = (int) file.length();

byte[] bytes = new byte[length];

FileInputStream in = new FileInputStream(file);
try {
    in.read(bytes);
} finally {
    in.close();
}

String contents = new String(bytes);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.