android面試(4)---檔案儲存體

來源:互聯網
上載者:User

標籤:

1.sharePreference?

SharedPreferences類,它是一個輕量級的儲存類,特別適合用於儲存軟體配置參數。

SharedPreferences儲存資料,其背後是用xml檔案存放資料,檔案存放在/data/data/<package name>/shared_prefs目錄下:

一個簡單的儲存代碼如下:

SharedPreferences sharedPreferences = getSharedPreferences("wujay", Context.MODE_PRIVATE); //私人資料
Editor editor = sharedPreferences.edit();//擷取編輯器
editor.putString("name", "wujaycode");
editor.putInt("age", 4);
editor.commit();//提交修改

四種操作模式分別為:

1. MODE_APPEND: 追加方式儲存

2. MODE_PRIVATE: 私人方式儲存,其他應用無法訪問

3. MODE_WORLD_READABLE: 表示當前檔案可以被其他應用讀取

4. MODE_WORLD_WRITEABLE: 表示當前檔案可以被其他應用寫入

SharedPreferences share=getSharedPreferences("Acitivity",Activity.MODE_WORLD_READABLE);

int i=share.getInt("i",0);

String str=share.getString("str","");

boolean flag=share.getBoolean("flag",false);

2.FILE IO?

FileoutputStream foutput = new FileoutputStream(filepath);//寫入foutput .close();FileinputStream finput = new FileinputStream(filepath);//讀取finput .close();

context.openfileoutput/context.openfileinput

/data/data/pacakagename/files/

imageview.setimagedrawable(sdfilepath);

3.xml 的幾種方式?

DOM,SAX,PULL方式。一般使用pull方式。

 

android面試(4)---檔案儲存體

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.