Android:adb pull错误,myfile.txt不存在
我正在开发一个应用程序,它可以进行一些繁重的 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
如果您尝试从本地应用程序目录中提取文件,您将收到权限错误,因为只有该应用程序对其自己的文件拥有权限
这将解决该问题:
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:
从 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 :)
该文件可能位于 /sdcard/myfile.txt 上,因为您将其存储在外部存储的根目录中(我假设是 sdcard)。尝试从那里提取文件:
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:
尝试Environment.getExternalStorageDirectory().getAbsolutePath();。
Try
Environment.getExternalStorageDirectory().getAbsolutePath();
.您可以通过进入 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.