File I/O

See Using the Internal Storage. A file created with Context.MODE_PRIVATE is born with the nine permissions rw-rw---- and can be read and written only by this app and by other apps with the same Linux user ID. To give another app the same Linux user ID as this app, see User IDs and File Access.

A file created with
Context.MODE_WORLD_READABLE | Context.MODE_WORLD_WRITEABLE
is born with the nine permissions rw-rw-rw- and can be read and written by other apps. The vertical bar is the “bitwise or” operator.

Source code in File.zip

  1. FileActivity.java
  2. R.java
  3. main.xml

Look at the files in the Android Emulator

adb shell
# pwd
/

# ls -l		minus lowercase l
dr-x------ root     root              2011-04-20 09:19 config
drwxrwx--- system   cache             2011-04-20 09:19 cache
lrwxrwxrwx root     root              2011-04-20 09:19 sdcard -> /mnt/sdcard
drwxr-xr-x root     root              2011-04-20 09:19 acct
drwxrwxr-x root     system            2011-04-20 09:19 mnt
lrwxrwxrwx root     root              2011-04-20 09:19 vendor -> /system/vendor
lrwxrwxrwx root     root              2011-04-20 09:19 d -> /sys/kernel/debug
lrwxrwxrwx root     root              2011-04-20 09:19 etc -> /system/etc
-rw-r--r-- root     root         3764 1969-12-31 19:00 ueventd.rc
-rw-r--r-- root     root            0 1969-12-31 19:00 ueventd.goldfish.rc
drwxr-xr-x root     root              2011-02-03 17:51 system
drwxr-xr-x root     root              1969-12-31 19:00 sys
drwxr-x--- root     root              1969-12-31 19:00 sbin
dr-xr-xr-x root     root              1969-12-31 19:00 proc
-rwxr-x--- root     root        13805 1969-12-31 19:00 init.rc
-rwxr-x--- root     root         1677 1969-12-31 19:00 init.goldfish.rc
-rwxr-x--- root     root        94168 1969-12-31 19:00 init
-rw-r--r-- root     root          118 1969-12-31 19:00 default.prop
drwxrwx--x system   system            2011-04-20 09:20 data
drwx------ root     root              2010-01-27 19:59 root
drwxr-xr-x root     root              2011-04-20 09:20 dev

# cd data/data/edu.nyu.scps.file

# pwd
drwxrwx--x app_34   app_34            2011-04-20 11:41 app_subdir
drwxr-xr-x system   system            2011-04-20 11:41 lib
drwxrwx--x app_34   app_34            2011-04-20 10:44 cache
drwxrwx--x app_34   app_34            2011-04-20 11:41 files

# ls -l
-rw-rw---- app_34   app_34          6 2011-04-20 11:46 filename.txt

# cat filename.txt
hello

# rm filename.txt

# ls -l filename.txt
filename.txt: No such file or directory

# exit