用于解析专有设置文件的库

时间:2011-06-30 04:28:01

标签: java parsing legacy

是否有任何免费库可用于解析如此描述的唯一设置文件(取自实际文件)。也许类似于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

2 个答案:

答案 0 :(得分:1)

您可以自己解析第一行,然后使用像opencsv这样的CSV-Parser,它使用#1行中的分隔符进行配置。

答案 1 :(得分:1)

此属性文件格式看起来足够自定义,因此您使用的任何解析库都会增加更多的复杂性。我的建议是你需要的唯一外部库是JUnit :)但是如果你真的想做一个学习练习结帐http://www.antlr.org/