プロパティキーをロードするクラスがあります。実行中は20秒間スリープ状態になり、スリープ状態でプロパティファイルに新しいキーを追加して保存します。プログラムが起動すると、再びプロパティファイルが読み込まれますが、その出力にはスリープ中に追加されたプロパティは表示されません。プロパティファイルの変更をプログラムに認識させるにはどうすればよいですか?プロパティファイルのスリープ
public class Test {
public static void main(String[] args) {
Properties props = new Properties();
InputStream is = Test.class.getClassLoader().getResourceAsStream(
"com/vijayspring/common/CityIns.properties");
try {
props.load(is);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(props.stringPropertyNames());
try {
Thread.sleep(20000);
} catch (InterruptedException e) {
e.printStackTrace();
}
Properties props1 = new Properties();
InputStream is1 = Test.class.getClassLoader().getResourceAsStream(
"com/vijayspring/common/CityIns.properties");
try {
props1.load(is1);
} catch (IOException e) {
e.printStackTrace();
}
System.out.println(props1.stringPropertyNames());
}
}
正確にプロパティファイルを保存しますか?そして、あなたは不変の場所からプロパティをロードすることを知っていますか? –
iamはプロジェクトのsrcフォルダに保存し、キーをロードしてコンソールに出力しています – amt14779
その部分を追加してください。あなたの質問には不可欠です。 –