AndroidStudio中存储和检索数据到内部存储时出现错误?
创始人
2024-08-20 15:30:21
0
  1. 确保已声明读写权限,可以在AndroidManifest.xml文件中添加以下代码:

  2. 检查数据是否已经写入内部存储。可以使用以下代码将数据写入内部存储: String filename = "myfile"; String fileContents = "Hello world!"; FileOutputStream outputStream;

try { outputStream = openFileOutput(filename, Context.MODE_PRIVATE); outputStream.write(fileContents.getBytes()); outputStream.close(); } catch (Exception e) { e.printStackTrace(); }

  1. 从内部存储中检测和检索数据。可以使用以下代码从内部存储中读取数据: String filename = "myfile"; String fileContents = "";

try { FileInputStream inputStream = openFileInput(filename);

int c; while ((c = inputStream.read()) != -1) { fileContents += Character.toString((char) c); } inputStream.close(); } catch (Exception e) { e.printStackTrace(); }

注意:以上代码片段应该放在Activity或Fragment的方法中。

相关内容

热门资讯

一分钟了解!hhpoker辅助... 一分钟了解!hhpoker辅助器,hh poker透视器下载,实用技巧(有挂攻略);《WPK辅助透视...
玩家亲测!aapoker免费透... 1、玩家亲测!aapoker免费透视脚本,wepoker有没有挂,曝光教程(有挂技巧)。2、aapo...
专业讨论!hhpoker脚本,... 专业讨论!hhpoker脚本,聚星ai辅助工具下载,科技教程(有挂技巧);小薇(透视辅助)致您一封信...
一分钟了解!德州局hhpoke... 此外,数据分析德州(德州局hhpoker)辅助神器app还具备辅助透视行为开挂功能,通过对客户德州局...
程序员教你!wepoker辅助... 程序员教你!wepoker辅助器下载,wepoker俱乐部辅助,可靠技巧(有挂软件);大神普及一款德...
玩家攻略推荐!impoker辅... 玩家攻略推荐!impoker辅助,uupoker有透视吗,AI教程(有挂透明);原来确实真的有挂(需...
最新通报!wepoker养号规... 最新通报!wepoker养号规律,we poker辅助器v3.3,总结教程(有挂技巧)1、很好的工具...
分享认知!wepoker开脚本... 自定义哈糖大菠萝辅助器系统规律,只需要输入自己想要的开挂功能,一键便可以生成出微扑克专用辅助器,不管...
玩家必看教程!wepoker有... 玩家必看教程!wepoker有辅助插件吗,xpoker辅助神器,揭秘教程(有挂技巧);wepoker...
必知教程!aa poker辅助... 必知教程!aa poker辅助,wepoker脚本,AI教程(有挂神器)关于aa poker辅助机制...