在 Java 中标记文本文件的最佳方法是什么?

发布于 2024-08-03 19:01:04 字数 419 浏览 2 评论 0原文

在 Java 中标记文本文件的最佳方法是什么

  1. 如果我想使用 java.io.Reader,而不是
  2. 返回字符串分隔符,那么

?我评估了以下类:

  • 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

  1. I want to work with a java.io.Reader, not a String
  2. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ぃ弥猫深巷。 2024-08-10 19:01:04

我认为在 Scanner 中有一个 next(Pattern p) 方法可以完成这项工作。只要找到正确的模式,它就会返回分隔符,您也可以重新指定标记。

I think in Scanner there is a next(Pattern p) method which may do the job. Just find correct Pattern and it will return delimiters and also you can re-specify tokens.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文