使用 BufferedReader 从文件中读取 Long 和 String
我的数据按以下语法存储在文件中:
12034567892410
asdf'gndzfm,ndsfgkmnds/fgmfgkjadf'jdakgjdafgj
.
.
.
其中数字实际上并未写为字符串,而是使用 writeLong 将其写为长整型。
我想使用 BufferedReader 从文件中读取这些数据。
有什么建议吗?
My Data is stored in a file in the following syntax:
12034567892410
asdf'gndzfm,ndsfgkmnds/fgmfgkjadf'jdakgjdafgj
.
.
.
Where the numbers are not actually written as strings, they are written as longs using writeLong.
I want to read these data from the file using BufferedReader.
Any Suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您将它们写为二进制数据,则无法使用 BufferedReader 可靠地读取它们,这适用于文本数据。听起来您可能想要
DataInputStream
。基本上,您的阅读代码应该与您的编写代码相匹配。如果您发布用于写入数据的代码,我们应该能够将相应的代码放在一起以再次读取它。If you wrote them as binary data, you can't reliably read them using
BufferedReader
, which is meant for text data. It sounds like you probably wantDataInputStream
. Basically, your reading code should match your writing code. If you post the code used to write the data, we should be able to put together the corresponding code to read it back again.