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

标签 android file path

我在私有(private)应用程序文件夹的 files 目录中有一个名为 abikor.txt 的文件:

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

如何获取这个文件的路径?

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

(一般情况下,如何获取私有(private)app目录下/files目录下的文件路径?)

亲切的问候

最佳答案

对于内部存储路径,您需要指定类似这样的内容

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

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

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

如果你想从中读取文件那么

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);

关于android - 从Android中的文件目录中的文件获取路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31850090/

相关文章:

安卓/ tensorflow : Why is RandomShuffleQueue needed for testing?

android - Jacoco 覆盖不适用于最新的 android 插件

python - 如何将文件读取到列表列表?

java - 制作可在 jar 中访问的文件夹

android - 在 android 中使用 CheckedTextView 需要帮助

java - 如何将图标添加到抽屉导航中的项目

C无法打开文本文件

c++ - 如何找到 C 中可执行文件的位置?

python - FFmpeg 在 Path 中,但在 CMD 中运行导致 "FFmpeg not recognized as internal or external command"

flutter - 如何使用 GestureDetect 在 Flutter 中点击 CustomPaint 路径?