private TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textView = (TextView) findViewById(R.id.showState);
try{
//在应用里创建一个自己的文件
File file = new File(getApplication().getFilesDir(), "test.txt");
file.createNewFile();
FileOutputStream outputStream=new FileOutputStream(file);
BufferedOutputStream bufferedOutputStream=new BufferedOutputStream(outputStream);
//将china转成二进制写入自己的应用级缓存里
bufferedOutputStream.write("china".getBytes());
bufferedOutputStream.close();
textView.setText("successfully!\n"+file.getAbsolutePath());
}catch(Exception exception){
exception.printStackTrace();
textView.setText("failed!");
}
}