第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

關(guān)于Android“外部存儲(chǔ)用戶信息”代碼注釋,請(qǐng)問(wèn)有知道的嗎?

關(guān)于Android“外部存儲(chǔ)用戶信息”代碼注釋,請(qǐng)問(wèn)有知道的嗎?

慕尼黑8549860 2022-06-01 11:07:33
public void onClick(View v) {File sdPath = Environment.getExternalStorageDirectory();File f = new File(sdPath, "data.txt");switch (v.getId()) {case R.id.btn_save:FileOutputStream fos;String saveinfo = et_info.getText().toString();try {fos = new FileOutputStream(f);fos.write(saveinfo.getBytes());fos.close();} catch (Exception e) {e.printStackTrace();}Toast.makeText(MainActivity.this, "數(shù)據(jù)保存成功", 0).show();break;case R.id.btn_read:String content = "";try {FileInputStream fis = new FileInputStream(f);byte[] buffer = new byte[fis.available()];fis.read(buffer);content = new String(buffer);fis.close();// BufferedReader br = new BufferedReader(new InputStream(fis)));// br.readLine();} catch (Exception e) {e.printStackTrace();}Toast.makeText(MainActivity.this, "保存的數(shù)據(jù)是:" + content, 0).show();break;default:break;}}
查看完整描述

1 回答

?
慕田峪7331174

TA貢獻(xiàn)1828條經(jīng)驗(yàn) 獲得超13個(gè)贊

public void onClick(View v) {
//獲取產(chǎn)生點(diǎn)擊事件的View的ID
switch (v.getId()) {
case R.id.btn_save://當(dāng)ID為保存按鈕的ID
//獲取EditText中的內(nèi)容(去除空格)
String saveinfo = et_info.getText().toString().trim();
FileOutputStream fos;
try {
//將內(nèi)容寫(xiě)入data.txt中,模式是寫(xiě)在原內(nèi)容尾處。
fos = openFileOutput("data.txt", Context.MODE_APPEND);
//saveinfo 轉(zhuǎn)化為字節(jié)流并通過(guò)fos寫(xiě)入對(duì)應(yīng)文件中
fos.write(saveinfo.getBytes());
fos.close();//關(guān)流
} catch (Exception e) {
e.printStackTrace();
}
//在屏幕上產(chǎn)生Toast
Toast.makeText(MainActivity.this, "數(shù)據(jù)保存成功", 0).show();
break;
case R.id.btn_read://當(dāng)ID為讀按鈕的ID時(shí)
String content = "";//初始化content
try {
//創(chuàng)建文件讀取流
FileInputStream fis = openFileInput("data.txt");
byte[] buffer = new byte[fis.available()];//新建byte數(shù)組,并設(shè)置大小。
fis.read(buffer);//通過(guò)流寫(xiě)入數(shù)組
content = new String(buffer);//給content初始化賦值
} catch (Exception e) {
e.printStackTrace();
}
Toast.makeText(MainActivity.this, "保存的數(shù)據(jù)是:" + content, 0)
.show();
break;
default://以后ID都不是時(shí),不采取操作。
break;
}
}


查看完整回答
反對(duì) 回復(fù) 2022-06-06
  • 1 回答
  • 0 關(guān)注
  • 147 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)