標籤:android 檔案儲存體
Android SDK 支援哪些檔案儲存體技術?
SharedPreferences、流檔案儲存體、XML半結構化儲存、JSON儲存、資料庫、第三方物件導向資料庫。
如何使用ShardPreferences存取key-value類型的資料?
//執行個體化SharedPreferences對象(第一步) SharedPreferences mySharedPreferences= getSharedPreferences("test", Activity.MODE_PRIVATE); //執行個體化SharedPreferences.Editor對象(第二步) SharedPreferences.Editor editor = mySharedPreferences.edit(); //用putString的方法儲存資料 editor.putString("name", "Karl"); editor.putString("habit", "sleep"); //提交當前資料 editor.commit();
//同樣,在讀取SharedPreferences資料前要執行個體化出一個SharedPreferences對象 SharedPreferencessharedPreferences= getSharedPreferences("test", Activity.MODE_PRIVATE); // 使用getString方法獲得value,注意第2個參數是value的預設值 String name =sharedPreferences.getString("name", ""); String habit =sharedPreferences.getString("habit", ""); //使用toast資訊氣球顯示資訊
SharedPreferences儲存的資料檔案存放在哪個目錄中?是否可以不使用SharedPreferences讀取這些資料檔案?
檔案儲存體路徑為data/data/packagename/shared_prefs
可以直接用檔案流讀取檔案。
Sharedpreferences是否可以把資料儲存在SD卡上?
可以用Java反射技術修改檔案儲存路徑。
SharedPreferences可以儲存映像資料嗎?
將映像轉化為位元據即可:
public byte[] getBitmapByte(Bitmap bitmap){ ByteArrayOutputStream out = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out); try { out.flush(); out.close(); } catch (IOException e) { e.printStackTrace(); } return out.toByteArray(); }
讀取:
-
public Bitmap getBitmapFromByte(byte[] temp){ if(temp != null){ Bitmap bitmap = BitmapFactory.decodeByteArray(temp, 0, temp.length); return bitmap; }else{ return null; } }
如何通過PreferencesActivity實現設定頁面?
http://www.jb51.net/article/31915.htm
PreferenceActivity儲存資料的預設檔案名稱是什嗎?如何更改?
packagename_preferences.xml。
用PreferenceManager.getSharedPreferencesName方法修改。
Android SDK支援哪些擷取檔案輸入輸出資料流的方式?
1:InputStream和OutputStream方式。
http://blog.csdn.net/ztp800201/article/details/7322110
2:Context.openFileOutput和Context.openFileInput對象。
http://blog.sina.com.cn/s/blog_6e5195850100zssn.html
SAX引擎分析XML文檔的過程?
初始化-->開始處理每一個XML元素-->處理完元素-->處理完檔案,完成收尾工作-->儲存XML元素的文本
如何將XML檔案轉換為Java對象?
http://showlike.iteye.com/blog/1050843
《Android面試寶典》學習筆記(第五章:檔案儲存體)