求求大佬救命,弄了几天不对,我自学的第一行代码,用Androidstudio 3.6.2

        public class MainActivity extends AppCompatActivity {
        private EditText edit;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        edit=(EditText)findViewById(R.id.edit);
    }
    protected void onDestroy(){
        super.onDestroy();
        String inputText=edit.getText().toString();
        save(inputText);
    }
    public void save(String inputText){
        FileOutputStream out=null;
        BufferedWriter writer=null;
        try{
            out=openFileOutput("data", Context.MODE_PRIVATE);
            writer=new BufferedWriter(new OutputStreamWriter(out));
            writer.write(inputText);
        }catch (IOException e){
            e.printStackTrace();
        }finally {
            try{
                if(writer!=null){
                    writer.close();
                }
            }catch (IOException e){
                e.printStackTrace();
            }
        }

    }
}
查看全部
qq_45072899
好吃,大大豆沙包!
2020/04/15 11:41
  • android-studio
  • 点赞
  • 收藏
  • 回答
    私信

1个回复