1、
为了将文件保存在文件中,要使用FileOutputStream类。
openFileOutput()方法用指定的模式,打开一个指定的文件来写入。
MODE_WORLD_READABLE常量来表示此文件可被其他所有应用程序读取:
public void onClickSave(View view){
String str = textBox.getText().toString();
try
{
FileOutputStream fOut = openFileOutput("textfile.txt",MODE_WORLD_READABLE);
OutputStreamWriter osw = new OutputStreamWriter(fOut);
//
osw.write(str);
osw.flush();
osw.close();
//
Toast.makeText(getBaseContext(),"File Saved Successfully", Toast.LENGTH_SHORT).show();
textBox.setText("");
}
catch(IOException e){
e.printStackTrace();
}
}