public class MainActivity extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
try {
/*得到一个文件的输出流,文件的位置/data/data/包名/files/haha.txt
* File file = new File(getFilesDir(),"haha.txt");
FileOutputStream fos = new FileOutputStream(file);*/
FileOutputStream fos = openFileOutput("readable.txt", MODE_WORLD_READABLE);
fos.write("dafa".getBytes());
fos.close();
fos = openFileOutput("writeable.txt", MODE_WORLD_WRITEABLE);
fos.write("dafa".getBytes());
fos.close();
fos = openFileOutput("public.txt", MODE_WORLD_WRITEABLE+MODE_WORLD_READABLE);
fos.write("dafa".getBytes());
fos.close();
fos = openFileOutput("private.txt", MODE_PRIVATE);
fos.write("dafa".getBytes());
fos.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}