从Android中的文件目录中的文件获取路径

7 android file path

我有一个文件名为abikor.txt内部files私人app文件夹目录:

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

如何获取此文件的路径?

我看到了以下问题,但它们没有解决我的问题.

(一般来说,如何获取存储在/files私有app目录下的目录下的文件的路径?)

亲切的问候

Sri*_*rni 9

对于内部存储路径,您需要指定一些类似的东西

String path = context.getFilesDir().getAbsolutePath();
Run Code Online (Sandbox Code Playgroud)

然后从路径创建一个文件对象

File file = new File(path + "/abikor.txt");
Run Code Online (Sandbox Code Playgroud)

如果你想从中读取该文件,然后

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);
Run Code Online (Sandbox Code Playgroud)