2

Beginner android question. Ok, I've successfully written files. E.g. // get the file name String filename = getResources().getString(R.string.filename);

        FileOutputStream toWriteTo;
        try {
            toWriteTo = openFileOutput(filename, MODE_WORLD_READABLE);
            // get the string to write
            String toWrite = getResources().getString(R.string.contentstowrite);
            toWriteTo.write(toWrite.getBytes());
            toWriteTo.close();

            ...         
               }
        catch (Exception ex) {
            Toast.makeText(HelloFilesAppActivity.this, "fail!", Toast.LENGTH_SHORT).show();
        }
        }});

And I've proved that it is there by reading it and displaying contents, even using getFilesDir() and displaying all of the files in the folder.

Everything I read says that the files are in /data/data//files/ But I cannot find them. (I'm on Windows XP). My install didn't use default locations because my C:\ is pretty full. I looked in C:\Documents and Settings\Mike\.android\avd and in the project folder and in the place I installed the SDK: D:\Program Files\Android\android-sdk-windows. So where is /data/data/ ?

I read that I can use ADB to push and pull files back and forth, but I'm using Eclipse ADT and I'd prefer to use something other than command line. The book I'm using seems to imply that you can use Eclipse but then proceeds to give the command-line commands.

I found info about the Project Explorer in the DDMS, but I don't see the files I have written.

I've been working under the assumption that I might want to create a text file using some other means in Windows that I would read with my App. So if the answer is "why do you want to do this?", that's what I'm after. Eventually a DB probably too (that's in the next chapter :-) ).

Do I have to use the ADB command line?

thanks

Mike

user613586
  • 23
  • 1
  • 3

2 Answers2

3

It's on your phone. Your phone has its own file system. If you are using an emulator, then it's on the emulated file system, which is completely separate from yours. Your only way to access the phone's (or emulator's) file system is via ADB (unless we're talking about the SD card, which however does NOT host /data/data).

Side note - if your phone is not rooted, you won't have access to a lot of stuff on /data/data. I suppose that you are using an emulator, which is "rooted" in the sense that you have full access to its filesystem.

EboMike
  • 76,846
  • 14
  • 164
  • 167
3

http://developer.android.com/guide/topics/data/data-storage.html

The method your using to get the directory you read/write to:

openFileOutput()

You can save files directly on the device's internal storage. By default, files saved to the internal storage are private to your application and other applications cannot access them (nor can the user). When the user uninstalls your application, these files are removed.

You'll want to save the files your working with to the SD card.

Try this:

getExternalStoragePublicDirectory Example

Blundell
  • 75,855
  • 30
  • 208
  • 233
  • Ok, I tried a simple external storage trying to make even simpler than the linked example (thanks!). My code is: – user613586 Feb 12 '11 at 19:37
  • File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS); File file = new File(path, "dummy2.txt"); try { path.mkdirs(); String loc = path.getAbsolutePath(); Toast.makeText(HelloFilesAppActivity.this, "External files are at: " + loc, Toast.LENGTH_LONG); // stick some text into the file. OutputStream os = new FileOutputStream(file); os.write(" yada yada".getBytes()); os.close(); Toast.makeText(... it works } catch (IOException e) { Toast.makeText(... it bombed } – user613586 Feb 12 '11 at 19:59
  • I get info that external files are at /mnt/sdcard/Download I see at C:\Documents and Settings\Mike\.android\avd\Android_Vanilla2.3.avd there is a file sdcard.img that has just been modified. But It's looking like I still need to use ADB to get the file? – user613586 Feb 12 '11 at 20:00
  • If you go the the DDMS view in android (whilst your emulator is running). Select the 'File Explorer' tab and you can see all the files within that sdcard.img file. – Blundell Feb 12 '11 at 20:13