aamiri
aamiri

Reputation: 2440

Android: adb pull error, myfile.txt does not exist

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

Upvotes: 1

Views: 7325

Answers (5)

marmor
marmor

Reputation: 28171

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 .

Upvotes: 2

Sergey Dryganets
Sergey Dryganets

Reputation: 919

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 :)

Upvotes: 1

jorgenfb
jorgenfb

Reputation: 2237

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 .

Upvotes: 0

Haphazard
Haphazard

Reputation: 10948

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.

Upvotes: 0

omermuhammed
omermuhammed

Reputation: 7385

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

Upvotes: 0

Related Questions