Android应用程序内部数据存储
我试图使用 Android 的内部存储器将长整型数组保存为文本文件,然后在不同的活动中访问该数组。注意到它被破坏后,我将问题隔离在下面的这段代码中。
long[] timings = {200, 400, 600, 1400};
try {
FileOutputStream fos = openFileOutput("timings", Context.MODE_PRIVATE);
OutputStreamWriter osw = new OutputStreamWriter(fos);
osw.write(Arrays.toString(timings));
osw.close();
FileInputStream fis = openFileInput("timings");
InputStreamReader isReader = new InputStreamReader(fis);
char[] buffer = new char[timings.length];
isReader.read(buffer);
textField.setText(Arrays.toString(buffer));
fis.close();
} catch (IOException e1) {
e1.printStackTrace();
}
设置为显示从文件中读取的内容的文本字段具有以下结果:
[[,2,0,0]
我期望的结果是上面的原始数组。我在这里做错了什么?任何帮助或建议将不胜感激。
I am attempting to save an array of longs as a text file using the Android's internal memory, and then access that array in a different activity. After noticing that was broken, I isolated the problem in this chunk of code below.
long[] timings = {200, 400, 600, 1400};
try {
FileOutputStream fos = openFileOutput("timings", Context.MODE_PRIVATE);
OutputStreamWriter osw = new OutputStreamWriter(fos);
osw.write(Arrays.toString(timings));
osw.close();
FileInputStream fis = openFileInput("timings");
InputStreamReader isReader = new InputStreamReader(fis);
char[] buffer = new char[timings.length];
isReader.read(buffer);
textField.setText(Arrays.toString(buffer));
fis.close();
} catch (IOException e1) {
e1.printStackTrace();
}
The text field that is set to display what is read from the file has the following result:
[[,2,0,0]
The result I expected was the original array from above. What am I doing wrong here? Any help or advice would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将 : 替换
为 :
我希望它会对您有所帮助。
Replace this :
with this :
I hope it will help you.