用于解析专有设置文件的库
是否有任何免费库可供我用来解析这样描述的独特设置文件(取自实际文件)。也许类似于 ini4j (也许 ini4j 的可定制性足以让我可以使用它?)。在我开始努力编写自己的文件之前先检查一下:(
/*** This file specifies settings used by the __. Each
/*** line is delimited by colons. This file contains global as well as
/*** program specific settings. First part is always the variable name.
/*** Second part can be a single or a wildcarded program id, in which
/*** case the setting will be program specific. In the case of global
/*** variables, the second part will be the actual setting. The third
/*** and subsequent parts will only appear for program specific variables
/*** and will be the settings for those variables. Any comments at the
/*** end of the line have to be preceded by a colon, in order to separate
/*** it from the rest of the line.
我的文件正文如下所示(仅是一个示例):
DELIMITER=;
FROM_DIR;msc*;/usr/foo/bar
FROM_DIR;msd*;/usr/foo/bar
LOG_DIR;ms*;/usr/foo/logs
DUMP_FLAG;N
MAX_JOBS;8
Is there any free library that I may leverage for parsing a unique settings file described like so (taken from actual file). Perhaps something like ini4j (perhaps ini4j is customizeable enough that I could use it maybe?). Just checking before I start slogging away at writing my own :(
/*** This file specifies settings used by the __. Each
/*** line is delimited by colons. This file contains global as well as
/*** program specific settings. First part is always the variable name.
/*** Second part can be a single or a wildcarded program id, in which
/*** case the setting will be program specific. In the case of global
/*** variables, the second part will be the actual setting. The third
/*** and subsequent parts will only appear for program specific variables
/*** and will be the settings for those variables. Any comments at the
/*** end of the line have to be preceded by a colon, in order to separate
/*** it from the rest of the line.
The body of my files look like this (just an example):
DELIMITER=;
FROM_DIR;msc*;/usr/foo/bar
FROM_DIR;msd*;/usr/foo/bar
LOG_DIR;ms*;/usr/foo/logs
DUMP_FLAG;N
MAX_JOBS;8
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这种属性文件格式看起来足够自定义,您使用的任何解析库都会增加其值得的复杂性。我的建议是,您需要的唯一外部库是 JUnit :) 但是,如果您确实想做学习练习,请查看 http:// /www.antlr.org/
This property file format looks sufficiently custom that any parsing library you go with will add more complexity that it is worth. My recommendation is the only external library you need here is JUnit :) However if you really want to do a learning exercise checkout http://www.antlr.org/
您可以自己解析第一行,然后使用像 opencsv 这样的 CSV 解析器,它是使用行中的分隔符配置的#1.
You could parse the first line yourself and then use a CSV-Parser like opencsv, which is configured using the delimiter in line #1.