如何使用Android Device Monitor的文件资源管理器查找我的应用程序/数据/数据

Ger*_*ard 12 android adb android-studio

我有一个应用程序将文本文件写入内部存储.我想仔细看看我的电脑.

我运行了一个Toast.makeText来显示路径,它说:/ data/data/mypackage

但是当我转到Android Studio的Android Device Monitor应用程序时,我在文件资源管理器中看不到/ data/data.那我的文件在哪里?

我知道它们存在是因为我可以在adb shell上找到它.我需要将/ data/data转换为文件资源管理器中可见的路径,以便我可以轻松下载它们.谢谢!

Sky*_*net 5

您只能检查是否有root电话,因为这些文件夹是应用程序专用的,并且通常只能访问此类文件夹.我建议你是否没有root手机,然后复制你的内部文件夹并将它们写入SDCard以检查内容.另一种方法是根电话或使用模拟器.

以下是可用于在外部SD卡上写入副本的代码:

public static void copyDirectoryOneLocationToAnotherLocation(File sourceLocation, File targetLocation)
            throws IOException {

        if (sourceLocation.isDirectory()) {
            if (!targetLocation.exists()) {
                targetLocation.mkdir();
            }

            String[] children = sourceLocation.list();
            for (int i = 0; i < sourceLocation.listFiles().length; i++) {

                copyDirectoryOneLocationToAnotherLocation(new File(sourceLocation, children[i]),
                        new File(targetLocation, children[i]));
            }
        } else {

            InputStream in = new FileInputStream(sourceLocation);

            OutputStream out = new FileOutputStream(targetLocation);

            // Copy the bits from instream to outstream
            byte[] buf = new byte[1024];
            int len;
            while ((len = in.read(buf)) > 0) {
                out.write(buf, 0, len);
            }
            in.close();
            out.close();
        }

    }
Run Code Online (Sandbox Code Playgroud)