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的方法中。

相关内容

热门资讯

透视安卓版!cloudpoke... 透视安卓版!cloudpoker作弊,约局吧德州真的存在透视吗(其实真的有挂)1、点击下载安装,约局...
aapoker有挂!aapok... aapoker有挂!aapoker有手游版吗,(AAPOKEr)总是是有挂,详细教程(有挂方法);小...
透视最新!xpoker怎么作弊... 透视最新!xpoker怎么作弊,cloudpoker怎么开挂(总是有挂);1、cloudpoker怎...
aapoker有猫腻!aapo... aapoker有猫腻!aapoker智能ai辅助,(AAPOKER)其实是有挂,详细教程(有挂详情)...
透视存在!哈糖大菠萝有挂吗,f... 透视存在!哈糖大菠萝有挂吗,fishpoker透视底牌(都是是有挂)小薇(透视辅助)致您一封信;亲爱...
aapoker有外 挂!aap... aapoker有外 挂!aapoker辅助工具,(aapOker)确实有挂,详细教程(有挂方法)1、...
透视中牌率!佛手在线有挂吗,p... 透视中牌率!佛手在线有挂吗,pokerworld软件(竟然是真的有挂)1、该软件可以轻松地帮助玩家将...
aapoker有猫腻!德州aa... aapoker有猫腻!德州aa扑克透明挂,(aaPOKER)竟然是真的有挂,详细教程(有挂黑科技)1...
透视存在!newpoker脚本... 透视存在!newpoker脚本,德州私人局脚本(切实真的有挂)1、下载好德州私人局脚本辅助软件之后点...
aapoker有挂!德州aa辅... 1、aapoker有挂!德州aa辅助,(aapoKER)确实真的有挂,详细教程(有挂了解)。2、aa...