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

相关内容

热门资讯

透视实锤"wejok... 透视实锤"wejoker开挂"详细辅助细节方法(插件下载软件);亲真的是有正版授权,小编(透视辅助软...
透视规律"pokem... 透视规律"pokemmo免费脚本"详细辅助详细教程(透视最简单三个步骤神器)1、不需要AI权限,帮助...
透视美元局"wepo... 透视美元局"wepoker透视破解版"详细辅助2025新版教程(私人局辅助透明);wepoker透视...
透视存在"wepok... 1、透视存在"wepoker私人局辅助"详细辅助AI教程(免费脚本咨询神器)。2、wepoker私人...
透视计算"wepok... 透视计算"wepoker辅助脚本"详细辅助微扑克教程(htx矩阵辅助辅助);1.wepoker辅助脚...
辅助透视"poker... 辅助透视"poker world辅助"详细辅助2025新版(脚本技巧)1、玩家可以在poker wo...
辅助透视"wpk模拟... 辅助透视"wpk模拟器多开"详细辅助力荐教程(辅助是真的辅助)1、许多玩家不知道wpk模拟器多开辅助...
透视透视"来玩德州破... 透视透视"来玩德州破解器"详细辅助扑克教程(俱乐部辅助技巧)1、玩家可以在来玩德州破解器软件透明挂俱...
辅助透视"拱趴大菠萝... 辅助透视"拱趴大菠萝挂"详细辅助曝光教程(究竟有透视神器);1分钟了解详细教程(微信 1367043...
透视游戏"wepok... 透视游戏"wepoker有辅助功能吗"详细辅助AA德州教程(透视脚本神器);科技安装教程;13670...