的文件资源管理器查找我的应用程序的

的文件资源管理器查找我的应用程序的

本文介绍了如何使用 Android Device Monitor 的文件资源管理器查找我的应用程序的/data/data的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have an app that writes to text files onto Internal storage. I'd like to take a close look on my computer.

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

I ran a Toast.makeText to display the path, it says:/data/data/mypackage

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

But when I go to Android Studio's Android Device Monitor application, I don't see /data/data in the File Explorer. So where are my files?

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

I know they exist because I can find the on adb shell. I need to translate /data/data to a path visible on File Explorer, so that I can download them easily. Thanks!

推荐答案

您只能检查是否有 root 手机,因为这些文件夹是应用程序私有的,并且通常访问仅限于这些文件夹.如果您没有root手机,我会建议您复制您的内部文件夹并将它们写入您的SDCard以检查内容.另一种方法是root你的手机或使用模拟器.

You can only check that if you have a rooted phone, because these folders are private to applications and usual access is restricted to such folders. I would advise if you dont have a rooted phone then make a copy of your internal folders and write them to your SDCard to check the contents. The other way is to root your phone or use an Emulator.

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

Here is the code you can use to write a copy on your External SDCard:

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

    }

这篇关于如何使用 Android Device Monitor 的文件资源管理器查找我的应用程序的/data/data的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 09:42