1:SharedPreferences存储数据。
2:ContentProvider存储
3:文件存储
4:SQLlite存储
5:网络存储
按照个人理解,SharedPreferences存储数据原来上来说属于内部存储,所以可以理解为
1:内部存储
2:ContentProvider存储
3:外部存储
4:SQLlite存储
5:网络存储

1:SharedPreferences存储数据。这个简单,而且因为是内存存储,所以特别快
SharedPreferences sp = getSharedPreferences("mysp", Context.MODE_PRIVATE);
内部存储:速度突出一个快
private void saveCurrentText(){ try { OutputStream os = openFileOutput("data", Context.MODE_PRIVATE); os.write(et.getText().toString().getBytes("utf-8")); os.flush(); os.close(); Toast.makeText(this, "保存成功", Toast.LENGTH_SHORT).show(); return; } catch (FileNotFoundException e) { e.printStackTrace(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } Toast.makeText(this, "保存失败", Toast.LENGTH_SHORT).show(); }
private void readSavedText(){ try { InputStream is = openFileInput("data"); byte[] bytes = new byte[is.available()]; is.read(bytes); is.close(); String str = new String(bytes,"utf-8"); et.setText(str); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
2:ContentProvider存储
本博客其他的文章已经介绍过了,这里就不讲了
3:文件存储
上面直接上个读写SD卡的例子吧(只能读写小文件,否则内存就超了)
File dir = Environment.getExternalStorageDirectory(); File dataFile = new File(dir, "data.txt"); //read try { FileInputStream fis = new FileInputStream(dataFile); byte[] bytes = new byte[fis.available()]; fis.read(bytes); fis.close(); String str = new String(bytes,"utf-8"); System.out.println(str); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } //write try { if (!dataFile.exists()) { dataFile.createNewFile(); } FileOutputStream fos = new FileOutputStream(dataFile); fos.write(new String("Hello eoe").getBytes("utf-8")); fos.flush(); fos.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); }
4:SQLlite存储
只要mysql或者oracle语句使用的多了,也没有太大问题,注意使用后关掉就行了,另外还特意写了篇文章介绍sqlite,

5:网络存储,就是使用webservice解析的数据,或者从http协议中直接拿到的数据。