【问题标题】:How do I get path to /data/data folder android如何获取 /data/data 文件夹 android 的路径
【发布时间】:2019-07-28 17:12:04
【问题描述】:

我有一些 epub 文件保存到 android 内部存储中。我一直在使用folioReader 库来显示这些文件,但它一直告诉我路径目标为空。

所以,我检查了 android studio 的 Device File Explorer 并找到了这个位置的文件:/data/data/packageName/files/FileName

我正在使用此代码获取路径:

try{
            String path = getFilesDir().getPath() + "/" + fileName
            folioReader.openBook(path);
                Log.i("Path:", path);
        } catch (Exception e){
            e.printStackTrace();
        }
    }

它在我的log cat: 上返回此路径

/data/user/0/packageName/files/fileName

位置路径似乎有所不同。

所以,我的问题是:如何获得到该位置的路径?

/data/data/packageName/files/FileName

【问题讨论】:

    标签: epub internal-storage


    【解决方案1】:
    private String getFilePath(){
        ContextWrapper contextWrapper = new ContextWrapper(getApplicationContext());
        File filePath = contextWrapper.getFilesDir();
        File file = new File(filePath,"fileName" +"*/*");
        return file.getPath();
    }
    

    这里 'filePath' 包含 '/data/data/packageName/files/' 位置 然后用 '/fileName' 加入它会给出该文件的整个存储路径

    */ * 告诉 'fileName' 可以是任何文件类型

    【讨论】:

    • 请在您的答案中添加一些解释,以便其他人可以从中学习
    猜你喜欢
    • 2020-08-09
    • 2020-07-01
    • 1970-01-01
    • 2011-06-03
    • 2014-08-30
    • 1970-01-01
    • 1970-01-01
    • 2014-05-19
    • 1970-01-01
    相关资源
    最近更新 更多