1. 程式人生 > >android學習----主要資料儲存方

android學習----主要資料儲存方

//資料存入File檔案   
FileOutputStream outStream= this.openFileOutput("text.text", MODE_PRIVATE);
outStream.write("hello".getBytes());
outStream.close();
//file取資料
FileInputStream inStream =this.openFileInput("text.text");
ByteArrayOutputStream bOutStream=new ByteArrayOutputStream();
byte[] buffer=new byte[1024];
int length=0;
while((length=inStream.read(buffer))!=-1){
bOutStream.write(buffer, 0, length);
}
inStream.close();
bOutStream.close();