存储阵列在Java中的文件 [英] storing an array in a file in java

查看:103
本文介绍了存储阵列在Java中的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我打算存储数字数组中的文件,并在需要时阅读。什么是做到这一点的好办法?我能想到的办法当场打死,如在一条线上的每个元素存储为文本文件或通过该方法序列化和存储/调用。速度是我的第一个问题。

I plan to store an array of numbers in a file and read it when needed. What would be a good way to do this? I can think of afew ways such as storing each element in a line as a text file or serialize it and store / call by that method. Speed is my first concern.

感谢

推荐答案

如果该文件并不需要是人类可读的,那么其序列将是更好的办法性能明智的。
如果您想每个数组条目作为行保存在一个文件,你需要遍历数组,
做一些IO,保存文件,之后将其恢复,你需要做的反向所有茨艾伦步骤完全相同的数组。
此外,IO操作是相当昂贵的。

If the file doesn't need to be human-readable, then serializing it would be the better approach performance wise. If you would save every array entry as a line in a file, you would need to traverse the array, do some IO, save the file, later to restore it as the exact same array you would need to do all thos steps in reverse. Furthermore, IO operations are fairly expensive.

内置的序列化机制做这一切都为你和可以说是最有效的方式可能。

The built-in serialization mechanism does all this for you and arguably in the most effective way possible.

这篇关于存储阵列在Java中的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆