当前位置:网站首页>Fileoutputstream (file storage) and FileInputStream (file reading)
Fileoutputstream (file storage) and FileInputStream (file reading)
2022-07-27 19:52:00 【Ashurol】
public class MainActivity extends ActionBarActivity {
Button bt;
TextView tv;
EditText et;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
bt=(Button) findViewById(R.id.button1);
tv=(TextView) findViewById(R.id.textView1);
et=(EditText) findViewById(R.id.editText1);
bt.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
save(et.getText().toString());
tv.setText(Reader());
}
});
}
// Save the file
public void save(String content)
{
try {
FileOutputStream fos = openFileOutput("a.txt", MODE_PRIVATE);
fos.write(content.getBytes());// Will a string The characters contained in the string of type are converted to byte Type and store in a byte Array .
fos.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
// Read the file
public String Reader()
{
String content=null;
try {
FileInputStream fis=openFileInput("a.txt");
ByteArrayOutputStream bos=new ByteArrayOutputStream();
byte[] b=new byte[1024];
int len=0;
while((len=fis.read(b))!=-1)// Read data and write to array buffer, Judge when fis Whether the reading is finished , Play the role of cache
{
bos.write(b, 0, len);// Write array bytes to ByteArrayOutputStream In object
}
content=bos.toString();
fis.close();
bos.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return content;
}
}


边栏推荐
- 英特尔推出全球最小的高分辨率激光雷达,售价仅349美元
- [basic knowledge of deep learning - 44] the method of realizing multiple classification by logistic regression
- dp(动态规划)
- Transaction log full problem handling in sqlserver 2008
- 台积电5nm即将量产:苹果A14独占7成产能,华为麒麟1020拿下3成
- 开启和禁用hyper-v
- [basic knowledge of deep learning - 38] the difference between L1 regularization and L2 regularization
- 【深度学习基础知识 - 47】贝叶斯网络与朴素贝叶斯
- [basic knowledge of deep learning - 47] Bayesian networks and naive Bayes
- 三星将推多款RISC-V架构芯片,5G毫米波射频芯片会率先采用
猜你喜欢

Make your chat bubbles colorful
![[basic knowledge of deep learning - 46] Bayesian theorem and conditional probability formula](/img/9f/b9d7503404e068495fd8613df29366.png)
[basic knowledge of deep learning - 46] Bayesian theorem and conditional probability formula
![[basic knowledge of deep learning - 43] concept of odds ratio](/img/74/d7d1562ada4671864961721b9a1baf.png)
[basic knowledge of deep learning - 43] concept of odds ratio

Flink introduction and operation architecture

访问控制

Detailed interpretation of IEC104 protocol (I) protocol structure

ToggleButton(按钮开关)
![[basic knowledge of deep learning - 42] detailed explanation of logistic regression](/img/74/d7d1562ada4671864961721b9a1baf.png)
[basic knowledge of deep learning - 42] detailed explanation of logistic regression

Debian recaptured the "debian.community" domain name, but it's still not good to stop and rest
![[RCTF2015]EasySQL-1|SQL注入](/img/69/aa1fc60ecf9a0702d35d876e8c3dda.png)
[RCTF2015]EasySQL-1|SQL注入
随机推荐
[basic knowledge of in-depth learning - 40] Why does CNN have more advantages than DNN in the field of images
Fzu1669 right angled triangle
【深度学习基础知识 - 38】L1正则化和L2正则化的区别
BroadcastReceiver(广播)
Oracle 简单的高级查询
[basic knowledge of deep learning - 38] the difference between L1 regularization and L2 regularization
JS find all nodes sibling childNodes children
英特尔未来10年工艺路线图曝光:2029年推出1.4nm工艺!如何实现?
The valuation exceeds 15.6 billion yuan! Huaqin communication completed the round B financing of 1billion yuan! Qualcomm venture capital, Intel Capital led investment
ContentProvider of four components
【深度学习基础知识 - 50】PCA降维 主成成分分析
Uncover the mystery of Qualcomm ultrasonic fingerprint being "cracked by film"
OneNote code highlighting
细数国产接口协作平台的六把武器!
Object常用方法学习【clone和equals】
IEC104 规约详细解读(一) 协议结构
四大组件之ContentProvider
DatePicker(日期选择器)与TimePicker(时间选择器)
二叉搜索树
vlan试验2021.1.14