Skip to content

Commit

Permalink
#7 #788 第7次实验
Browse files Browse the repository at this point in the history
  • Loading branch information
wufchun committed Apr 22, 2019
1 parent 3e96bd5 commit 7c437d2
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}

0 comments on commit 7c437d2

Please sign in to comment.