Android:adb pull错误,myfile.txt不存在

发布于 2024-11-14 03:17:19 字数 898 浏览 4 评论 0原文

我正在开发一个应用程序,它可以进行一些繁重的 html 解析。我想确保 html 和 css 的格式正确(我有充分的理由相信它们不是)。使用 logcat 并不是特别有用,因为有大量文本需要筛选。所以我想为什么不将其写入文件,然后(用我的眼睛)读取该文件以查看它是否看起来已写入。我相信 adb pull 是将文件从我的模拟器拉到我的桌面上的命令。 Windows 7 是我的开发操作系统。当我使用 adb pull 'myfile.txt' 时,出现错误,提示我的文件不存在。这是我编写的用于创建文本文件的 java 函数:

private void cbdLog(String s){
    File root = Environment.getExternalStorageDirectory();
    if(root.canWrite()){

        try {
            File cbdLog = new File(root, "myfile.txt");
            FileWriter logWriter = new FileWriter(cbdLog);
            BufferedWriter out = new BufferedWriter(logWriter);
            out.write(s);
            out.close();
            Log.d("YO!", "Log file has been written");
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    else{
        Log.d("YO!", "Loggin failed");
    }
}

I'm developing an app that does some heavy html parsing. I want to make sure that the html and css have been properly formatted (I have strong reason to believe they are not). using logcat is not particularly helpuful since there is a great deal of text to sift through. So I thought why not write it to a file and then read that file (with my eyes) to see if it looks write. I believe adb pull is the command that will pull the file off of my emulator and onto my desktop. Windows 7 is my development operating system. When I use adb pull 'myfile.txt' I get an error that says my file doesn't exist. Here's the java function I wrote to create the text file:

private void cbdLog(String s){
    File root = Environment.getExternalStorageDirectory();
    if(root.canWrite()){

        try {
            File cbdLog = new File(root, "myfile.txt");
            FileWriter logWriter = new FileWriter(cbdLog);
            BufferedWriter out = new BufferedWriter(logWriter);
            out.write(s);
            out.close();
            Log.d("YO!", "Log file has been written");
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    else{
        Log.d("YO!", "Loggin failed");
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

快乐很简单 2024-11-21 03:17:20

如果您尝试从本地应用程序目录中提取文件,您将收到权限错误,因为只有该应用程序对其自己的文件拥有权限

这将解决该问题:

> adb shell
shell $ run-as com.contapps.android
shell $ chmod 666 databases/file
shell $ exit                                               ## exit out of 'run-as'
shell $ cp /data/data/package.name/databases/file /sdcard/
shell $ run-as com.contapps.android
shell $ chmod 600 databases/file
> adb pull /sdcard/file .

If you're trying to pull a file from a local app dir, you'll get permission error, since only the app has permission for its own files

This will solve the issue:

> adb shell
shell $ run-as com.contapps.android
shell $ chmod 666 databases/file
shell $ exit                                               ## exit out of 'run-as'
shell $ cp /data/data/package.name/databases/file /sdcard/
shell $ run-as com.contapps.android
shell $ chmod 600 databases/file
> adb pull /sdcard/file .
GRAY°灰色天空 2024-11-21 03:17:20

从 4.4 开始,无法将文件从 run-as 复制到 sdcard
所以现在我将文件权限更改为 666
chmod 666 file_name

并使用
adb pull 具有文件的完整路径,

因为 5.0 pull 对于此类文件不起作用。

我转移到 adb shell cat path_to_file_on_android_fs > path_on_local_fs

对我来说仍然有效:)

Since 4.4 there is no way to copy file to the sdcard from run-as
so now I change file permition to 666 with
chmod 666 file_name

and use
adb pull with full path to the file

since 5.0 pull for such files doesn't work.

And I moved to adb shell cat path_to_file_on_android_fs > path_on_local_fs

that still works for me :)

白芷 2024-11-21 03:17:20

该文件可能位于 /sdcard/myfile.txt 上,因为您将其存储在外部存储的根目录中(我假设是 sdcard)。尝试从那里提取文件:

adb pull /sdcard/myfile.txt .

The file will probably be located on /sdcard/myfile.txt since you are storing it on the root of the external storage (which is the sdcard I assume). Try pulling your file from there:

adb pull /sdcard/myfile.txt .
很酷不放纵 2024-11-21 03:17:20

尝试Environment.getExternalStorageDirectory().getAbsolutePath();。

Try Environment.getExternalStorageDirectory().getAbsolutePath();.

可可 2024-11-21 03:17:20

您可以通过进入 DDMS 透视图并选择文件视图来从模拟器中拖放文件。你的文件应该在某个地方。

You can drag&drop files from the emulator by going into the DDMS perspective and selecting the file view. Your file should be in there somewhere.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文