有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

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

是否有任何免费的库,我可以利用它来解析这样描述的唯一设置文件(取自实际文件)。也许像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) 个答案

  1. # 1 楼答案

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

  2. # 2 楼答案

    您可以自己解析第一行,然后使用类似opencsv的CSV解析器,该解析器是使用第#1行中的分隔符配置的