安卓文件存储

【安卓文件存储】千磨万击还坚劲,任尔东西南北风。这篇文章主要讲述安卓文件存储相关的知识,希望能为你提供帮助。
package com.example.sql_file_Input;
import java.io.BufferedWriter;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import com.example.sql_file.R;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.widget.EditText;
public class MainActivity extends Activity {
private EditText edit;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
edit = findViewById(R.id.edit);
}
@Override
protected void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
String inputText=edit.getText().toString();
save(inputText);
}
private void save(String inputText) {
FileOutputStream out=null;
BufferedWriter write=null;
try {
out=openFileOutput("data.txt",Context.MODE_PRIVATE);
write=new BufferedWriter(new OutputStreamWriter(out));
write.write(inputText);
if (write != null) {
write.close(); //文件编写完必须关闭
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}


































    推荐阅读