3

私のプロジェクトには、次のようなエントリを持つプロパティ ファイルがあります。

#Data key entries
datakey001
datakey321
datakey451
someotherkey

実際には、キーと値のペアではなく、キーのリストです。を使用java.util.Propertiesして、これを取得できましたProperties.stringPropertyNames()

現在、Apache Commons Configuration に移行していますが、以前はjava.util.Properties.

プロパティファイルの構造を変更せずにこれらすべてのキーを取得できるapache commons configに方法はありますか?

編集:私はConfiguration.getKeys()以下のように使用しようとしましたが、出力は空です。

 Configuration propertiesConfig = new PropertiesConfiguration("C:\\proj\\myprops.properties");
 Iterator<String> it = propertiesConfig.getKeys();
 while(it.hasNext()) {
     System.out.println(it.next());
 }
4

1 に答える 1

2

Configuration.getKeys() そのためにメソッドを使用できます。

于 2015-08-19T05:26:25.467 に答える