私が見ているように、Properties
は に縛られすぎていHashtable
ます。の順に読むことをお勧めしLinkedHashMap
ます。そのためには、 をキー/値コンテナーとして無視してObject put(Object key, Object value)
、単一のメソッド をオーバーライドするだけで済みます。Properties
public class InOrderPropertiesLoader<T extends Map<String, String>> {
private final T map;
private final Properties properties = new Properties() {
public Object put(Object key, Object value) {
map.put((String) key, (String) value);
return null;
}
};
public InOrderPropertiesLoader(T map) {
this.map = map;
}
public synchronized T load(InputStream inStream) throws IOException {
properties.load(inStream);
return map;
}
}
使用法:
LinkedHashMap<String, String> props = new LinkedHashMap<>();
try (InputStream inputStream = new FileInputStream(file)) {
new InOrderPropertiesLoader<>(props).load(inputStream);
}