-
Notifications
You must be signed in to change notification settings - Fork 229
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
...0902414/app/src/main/java/edu/hzuapps/androidlabs/soft1714080902414/DatasaveActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...4/app/src/main/java/edu/hzuapps/androidlabs/soft1714080902414/WordtestanswerActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |