Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
779221136 committed May 15, 2018
1 parent c29c7e5 commit 2f04ab2
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 6 deletions.
Binary file added soft1614080902416/app/5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added soft1614080902416/app/52.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import android.content.ContextWrapper;
import android.content.Intent;
import android.widget.TextView;
import android.widget.Spinner;
import java.io.BufferedWriter;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;

public class soft1614080902416Activity extends AppCompatActivity {
//
Expand Down Expand Up @@ -211,11 +219,13 @@ public void onClick(View view) {
switch(tag){
//全部清除
case 14:
x=0;
y=0;
text="";
zestatus=true;
break;
//调用保存的方法
savenumber(text);
// x=0;
// y=0;
// text="";
// zestatus=true;
// break;
case 15:
text=text.substring(0,text.length()-1);
break;
Expand Down Expand Up @@ -264,6 +274,28 @@ public boolean onOptionsItemSelected(MenuItem item) {
return super.onOptionsItemSelected(item);
}

//保存的方法
public void savenumber(String text){
FileOutputStream out=null;
BufferedWriter writer=null;
try{

out=openFileOutput("number", ContextWrapper.MODE_APPEND);
writer=new BufferedWriter(new OutputStreamWriter(out));
writer.write(text);
}catch (IOException e){
e.printStackTrace();
}finally {
try {
if(writer!=null){
writer.close();
}
}catch (IOException e){
e.printStackTrace();
}
}
}



}
2 changes: 1 addition & 1 deletion soft1614080902416/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<string name="app_name">soft1614080902416加法计算器</string>
<string name="action_settings">Settings</string>
<string name="c_ce">C</string>
<string name="c_c">C</string>
<string name="c_c">保存</string>
<string name="c_xx">%</string>
<string name="c_div">÷</string>

Expand Down
33 changes: 33 additions & 0 deletions soft1614080902416/report5.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@





##第五次实验

1.实验目标

(1)掌握在Android App中存储数据

2.实验步骤

(1)本次实验首先由于之前做的是计算器,所以决定把计算器中的一个按钮‘C’改为”保存“的按钮,具有保存屏幕上输入数字的功能

(2)在原soft1614080902416Activity中定义了 方法savenumber(String text)

(3)方法savenumber(String text)中运用了FileOutputStream流定义名字为“number”的文本,BufferedWriter writer的write写入数字

(4)在点击按钮“保存”时设置调用savenumber()方法,达到储存数字的效果。

(5)

## 3.实验结果
![screen](https://github.com/779221136/android-labs-2018/blob/master/soft1614080902416/app/5.png)
![screen](https://github.com/779221136/android-labs-2018/blob/master/soft1614080902416/app/52.png)

## 4.实验体会

学会了简单的存储,利用java.io类和流来输出数据,写入数据,和储存简单的数据,希望在以后的学习中能更多了解到储存的相关内容。



0 comments on commit 2f04ab2

Please sign in to comment.