數(shù)據(jù)存儲(chǔ)—讀寫內(nèi)部存儲(chǔ)的文件數(shù)據(jù)

android studio中打開DDMS

內(nèi)部存儲(chǔ)空間位置:

導(dǎo)航欄Tools->"Android"->"Android Device Monitor"->File Explorer->data->data->工程目錄

/***

可能出現(xiàn)DDMS無法連接相應(yīng)設(shè)備的情況,原因是真機(jī)或genymotion的root權(quán)限未打開

這篇博客解釋了原因:

http://blog.csdn.net/arex_efan/article/details/20008001

xda解釋的原因及提供的方法

http://forum.xda-developers.com/showthread.php?t=2528952

可自行在網(wǎng)絡(luò)上查找 genymotion-arm-translation_v1.1壓縮包

直接拖拽到genymotion模擬器頁面進(jìn)行安裝

(寶寶你的百度云里有)

重啟后

**/

activity_main:

Button

android:id="@+id/writBtn"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:text="保存數(shù)據(jù)"/>

Button

android:id="@+id/readBtn"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:text="讀取數(shù)據(jù)"/>

TextView

android:id="@+id/show"

android:layout_height="wrap_content"

android:layout_width="match_parent"/>


MainActivity.class:

privateEditTextet;

privateTextViewshow;

privateStringfilename="test";


protected voidonCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);


et= (EditText)findViewById(R.id.et);

show=(TextView)findViewById(R.id.show);

findViewById(R.id.writBtn).setOnClickListener(this);

findViewById(R.id.readBtn).setOnClickListener(this);

}

public voidonClick(View v) {

switch(v.getId()) {

caseR.id.writBtn:

try{

FileOutputStream fos =? openFileOutput(filename,Context.MODE_PRIVATE);

OutputStreamWriter osw =newOutputStreamWriter(fos,"UTF-8");

osw.write(et.getText().toString());

osw.flush();

fos.flush();

osw.close();

fos.close();

Toast.makeText(getApplicationContext(),"寫入完成",Toast.LENGTH_LONG).show();

}catch(FileNotFoundException e) {

e.printStackTrace();

}catch(UnsupportedEncodingException e) {

e.printStackTrace();

}catch(IOException e) {

e.printStackTrace();

}

break;

/***

* 注意關(guān)閉順序,先打開的后關(guān)閉

* fis.available 文件長(zhǎng)度

*/

caseR.id.readBtn:

try{

FileInputStream fis = openFileInput(filename);

InputStreamReader iis =newInputStreamReader(fis,"UTF-8");

charinput[] =new char[fis.available()];

iis.read(input);

iis.close();

fis.close();

String readed =newString(input);

show.setText(readed);

}catch(FileNotFoundException e) {

e.printStackTrace();

}catch(IOException e) {

e.printStackTrace();

}break;default:break;}}




最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 先說一下這篇文章里面的內(nèi)容:TCP 客戶端, 自定義對(duì)話框, 自定義按鈕, ProgressBar豎直顯示, 重力...
    楊奉武閱讀 3,897評(píng)論 0 3
  • ¥開啟¥ 【iAPP實(shí)現(xiàn)進(jìn)入界面執(zhí)行逐一顯】 〖2017-08-25 15:22:14〗 《//首先開一個(gè)線程,因...
    小菜c閱讀 7,295評(píng)論 0 17
  • Android 自定義View的各種姿勢(shì)1 Activity的顯示之ViewRootImpl詳解 Activity...
    passiontim閱讀 178,765評(píng)論 25 709
  • 今天中午搶到一個(gè)滿三十減七塊的券,沒忍住,果斷用了,現(xiàn)在吃的好熱啊…最近機(jī)器人基本都是測(cè)試了,優(yōu)化調(diào)試,明天計(jì)劃來...
    熊貓掰棒子閱讀 126評(píng)論 0 0
  • 泉州,繁華的經(jīng)濟(jì)地帶。 一座著名的寺廟,終日暮鼓梵音香火旺盛。東西兩塔默默地注視著眾多香客,眾多和尚…… 一個(gè)下雨...
    吼叫的胖閱讀 519評(píng)論 0 2

友情鏈接更多精彩內(nèi)容