在 Java 中标记文本文件的最佳方法是什么?
在 Java 中标记文本文件的最佳方法是什么
- 如果我想使用 java.io.Reader,而不是
- 返回字符串分隔符,那么
?我评估了以下类:
- java.util.StringTokenizer 满足 [2.],但不满足 [1.]
- java.util.Scanner 满足 [1.],但不满足 [2.]
- java.io.StreamTokenizer 似乎相当复杂。
实际上我不需要分隔符。我只需要知道,某个令牌在流结束之前是否可用,获取它,并获取该令牌之前的所有内容。应该可以逐个步骤重新指定令牌。
我查看了 Apache Commons、Google Code Search 和 Stack Overflow,但没有找到任何东西。
What is the best way to tokenize a text file in Java, if
- I want to work with a java.io.Reader, not a String
- Delimiters should be returned?
I have evaluated the following classes:
- java.util.StringTokenizer fulfills [2.], but not [1.]
- java.util.Scanner fulfills [1.], but not [2.]
- java.io.StreamTokenizer seems quite complicated.
I don't need delimiters, actually. I just need to know, if a certain token is available till the end of the stream, fetch it, and fetch everything that stands before the token. It should be possible to re-specify the token from step to step.
I have looked at Apache Commons, Google Code Search and Stack Overflow, but didn't find anything.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为在 Scanner 中有一个 next(Pattern p) 方法可以完成这项工作。只要找到正确的模式,它就会返回分隔符,您也可以重新指定标记。
I think in
Scanner
there is anext(Pattern p)
method which may do the job. Just find correct Pattern and it will return delimiters and also you can re-specify tokens.