安卓 内部数据存储
文件創(chuàng)建模式
| MODE_PRIVATE | 創(chuàng)建或替換文件 |
| MODE_APPEND | 文件不存在則創(chuàng)建文件,存在的話文件尾部追加內(nèi)容 |
FileOutputStream 類的某些公共方法
| void close() | 關(guān)閉調(diào)用流 |
| void write(byte[] buffer, int offset, int byteCount) | 將來自緩沖區(qū)的內(nèi)容寫到文件中,寫入內(nèi)容的字數(shù)為,WbyteCount參數(shù)指定的字節(jié)數(shù) |
| void write(byte[] buffer) | 將整個緩沖區(qū)的內(nèi)容寫入文件 |
| void write(int oneByte) | 將一個字節(jié)的內(nèi)容寫入到文件中 |
寫文件案例
// 寫文件 FileOutputStream openFileOutput = openFileOutput("myInternaldata.txt", MODE_PRIVATE); openFileOutput.write("666".getBytes()); openFileOutput.close();讀文件案例
FileInputStream openFileInput = openFileInput("myInternaldata.txt"); byte[] byte1 = new byte[openFileInput.available()]; // available 可以拿到文件的長度 if(openFileInput.read(byte1) != -1){String dada = new String(byte1);textView1.setText(dada); } openFileInput.close();總結(jié)
- 上一篇: 安卓 登录案例
- 下一篇: 微信小程序 提交表单