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

TT--
  • 2,956
  • 1
  • 27
  • 46

1 Answers1

15

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);
TechArcSri
  • 1,982
  • 1
  • 13
  • 20