源码下载(免下载积分):下载
 你可以直接存储数据到内部存储中,默认情况下,文件存储到内部存储中是私有的,不能被 
  其他程序访问,当卸载应用程序,这些文件会被移除。 
  创建并写入数据可以有两种方法:
     读文件也是基本相同的方式。 
     在读文件有一点小技巧:如果想在编译时保存一个静态文件在你的应用程序中,保存文件到 
  res/raw/directory.可以使用openRawResource()方法来打开文件,并返回一个InputStream 
  对象,然后就能读写数据了。 
 
代码: 
方法一:
FileOutputStream writeStream = null;
FileOutputStream fileOutputStream = null;
switch (view.getId()) {
    case R.id.button1:
    //创建的文件其他程序不能访问
    File file1 = new File(getFilesDir(),FILE1);
    try {
        //写入数据
        writeStream = new FileOutputStream(file1);
        writeStream.write("haha".getBytes());
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    finally{
        try {
            if (writeStream != null) 
                writeStream.close();
        } catch (IOException e) {
            e.printStackTrace();
    }
}方法二:
//使用的是android.content,
try {
    /*设置成MODE_PRIVATE,其他程序不能访问,这种是默认的构造方式,可以去设置成其他的方式来使其可读写。
    */
    fileOutputStream = openFileOutput(FILE2,Context.MODE_PRIVATE);
    //写入数据
    fileOutputStream.write("hehe".getBytes());
} catch (FileNotFoundException e) {
    e.printStackTrace();
} catch (IOException e) {
    e.printStackTrace();
}
finally{
    try {
        if (fileOutputStream != null)
            fileOutputStream.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}   存储缓存文件 
   如果想要缓存一些文件,你可以使用createTempFile()去创建文件,应该使用getCacheDir()去打开文件。 
小技巧:正常情况下,上述的文件无法看到,要想看到就要使用adb了,模拟器:adb devices查看设备
                ~$ adb devices 
                List of devices attached 
                emulator-5554    device
然后进入超级用户中,就可以做相应命令来查看了
                ~$ adb -s emulator-5554 shell 
                  # 
   注意:应用程序的内部存储目录是有应用程序的的包名制定的,默认的情况下,其他程序不能够访问内部 
            存储的路径,除非你显示的使用可读或者可写的模式。
参考资料:
http://developer.android.com/guide/topics/data/data-storage.html
http://developer.android.com/training/basics/data-storage/files.html
android数据存储_内部存储,布布扣,bubuko.com
原文地址:http://blog.csdn.net/wangfei199101/article/details/24849097