From 7c437d2a2e4b5157d564fffb632bc6fd8425e4df Mon Sep 17 00:00:00 2001 From: wufchun <1462803989@qq.com> Date: Mon, 22 Apr 2019 21:33:05 +0800 Subject: [PATCH] =?UTF-8?q?#7=20#788=20=E7=AC=AC7=E6=AC=A1=E5=AE=9E?= =?UTF-8?q?=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../soft1714080902414/DatasaveActivity.java | 63 +++++++++++++++++++ .../WordtestanswerActivity.java | 13 ++++ 2 files changed, 76 insertions(+) create mode 100644 students/soft1714080902414/app/src/main/java/edu/hzuapps/androidlabs/soft1714080902414/DatasaveActivity.java create mode 100644 students/soft1714080902414/app/src/main/java/edu/hzuapps/androidlabs/soft1714080902414/WordtestanswerActivity.java diff --git a/students/soft1714080902414/app/src/main/java/edu/hzuapps/androidlabs/soft1714080902414/DatasaveActivity.java b/students/soft1714080902414/app/src/main/java/edu/hzuapps/androidlabs/soft1714080902414/DatasaveActivity.java new file mode 100644 index 000000000..d00402c7f --- /dev/null +++ b/students/soft1714080902414/app/src/main/java/edu/hzuapps/androidlabs/soft1714080902414/DatasaveActivity.java @@ -0,0 +1,63 @@ +package edu.hzuapps.androidlabs.soft1714080902414; + +import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; +import android.view.View; +import android.widget.Button; +import android.widget.EditText; +import android.widget.Toast; + +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; + +public class DatasaveActivity extends AppCompatActivity implements View.OnClickListener { + private Button button1; + private Button button2; + private EditText editText1; + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_datasave); + button1=(Button) findViewById(R.id.bt1); + button2=(Button) findViewById(R.id.bt2); + editText1=(EditText) findViewById(R.id.et1); + button1.setOnClickListener(this); + button2.setOnClickListener(this); + } + + @Override + public void onClick(View view) { + switch (view.getId()) + { + case R.id.bt1: String save=editText1.getText().toString().trim(); + FileOutputStream fos; + try{ + fos=openFileOutput("data.txt",MODE_PRIVATE); + fos.write(save.getBytes()); + fos.close(); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + Toast.makeText( DatasaveActivity.this,"数据保存成功",Toast.LENGTH_SHORT).show(); + break; + case R.id.bt2: String content=""; + try { + FileInputStream fis=openFileInput("data.txt"); + byte[] buffer=new byte[fis.available()]; + fis.read(buffer); + content=new String(buffer); + fis.close(); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + Toast.makeText(DatasaveActivity.this,"保存的数据为"+content,Toast.LENGTH_SHORT).show(); + break; + } + } +} diff --git a/students/soft1714080902414/app/src/main/java/edu/hzuapps/androidlabs/soft1714080902414/WordtestanswerActivity.java b/students/soft1714080902414/app/src/main/java/edu/hzuapps/androidlabs/soft1714080902414/WordtestanswerActivity.java new file mode 100644 index 000000000..9aa0be483 --- /dev/null +++ b/students/soft1714080902414/app/src/main/java/edu/hzuapps/androidlabs/soft1714080902414/WordtestanswerActivity.java @@ -0,0 +1,13 @@ +package edu.hzuapps.androidlabs.soft1714080902414; + +import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; + +public class WordtestanswerActivity extends AppCompatActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_wordtestanswer); + } +}