Java - 使用Scanner读取大文本文件
我有一个非常大的文本文件,其中包含客户信息。我想从文本文件中读取所有客户信息。
这就是我的文本文件的组织方式:
Costomer 1:
Name:
Erik Andersson
Adress:
Street1
Phone number:
085610540
Costomer 2:
Name:
Lars Larsson
Adress:
Street1
Phone number:
085610540
我希望能够读取所有客户信息。有什么好的办法吗?我读过有关扫描仪和图案的内容,想知道在这种情况下使用它们是否是个好主意?我的文本文件非常大,包含数百个客户。
有人知道我如何从文本文件中读取所有信息吗?我创建了一个带有客户变量的类,我只需要帮助读取文本文件。我想以有组织的方式阅读信息。
非常感谢所有帮助。
I have a very big text file with customer information. I would like to read all the customer information from the text file.
This is how my text file is organized:
Costomer 1:
Name:
Erik Andersson
Adress:
Street1
Phone number:
085610540
Costomer 2:
Name:
Lars Larsson
Adress:
Street1
Phone number:
085610540
I would like to be able read all the customer information. Is there any good way to it with? I have read about Scanner and Pattern and was wondering if it is good idea to use them in this case? My text file is very big and contains hundreds of customers.
Dose any one have any idea how I could read all the information from the text file? I have created a class with customer variabled, I only need help with the reading from the text file. I want to read the information in an organized way.
All help is very very appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
像这样:
请给+1并更正你的硬件哈哈
Like so:
Please give +1 and correct for ur hw lol
作为stas答案的一个小扩展:
最初发布的代码不起作用,因为
继续
跳过当前循环迭代。因此,除非该行以""
开头,否则不会执行任何操作。As a little extension to stas answer:
The originally posted code doesn't work, because a
continue
skips the current loop-iteration. So unless the line starts with""
, nothing is ever done.