
新建文件存储数据:
//本地新建文件写入数据
try {
FileOutputStream fileOutputStream=openFileOutput("文件名",MODE_APPEND);
fileOutputStream.write(想要写入的数据);
fileOutputStream.close();
} catch (Exception e) {
e.printStackTrace();
}
读取文件数据:
try {
FileInputStream fileInputStream = openFileInput("文件名");//与写入对应写入时起的文件名,这里用写入时的名字读取的就是写入时的数据
byte[] bytes = new byte[fileInputStream.available()];
fileInputStream.read(bytes);
String content = new String(bytes);//将文件数据赋值给变量content,变量可在你需要且合适的地方定义
Log.i("fis",content);
} catch (Exception e) {
e.printStackTrace();
}
感谢您的来访,获取更多精彩文章请收藏本站。

© 版权声明
THE END
暂无评论内容