数据存储——文件存储

来源:互联网 发布:淘宝一淘网首页 编辑:程序博客网 时间:2024/06/05 16:42

1.写文件

String data = "testData";FileOutputStream fos = openFileOutput("test.txt",MODE_PRIVATE);fos.write(data.getBytes());fos.close();

2.读文件

String data = "";FileInputStream fis = openFileInput("test.txt");ByteArrayOutputStream baos = new ByteArrayOutputStream();byte[] buffer = new byte[1024];int length = 0;while((length = fis.read(buffer)) != -1){    baos.write(buffer,0,length);}data = baos.toString();
0 0