开发者

java properties

开发者 https://www.devze.com 2023-04-09 16:24 出处:网络
With properties in java how could I check if the value of the property is equal to something example if the property quitonload is equal to true then the p开发者_如何学Crogram will exit on startOr if

With properties in java how could I check if the value of the property is equal to something example if the property quitonload is equal to true then the p开发者_如何学Crogram will exit on start


Or if you're using a Properties file you can do this:

Properties p = new Properties()

p.load(new FileInputStream(args[0]))

if (p.getProperty("quitonload").equals("true")) {
  System.out.println("quitonload is true");
  System.exit(1);
}
System.out.println("quitonload is false");

Check the documentation on the Properties file if you have any doubts on the file format.


Do you mean something like:

if (System.getProperty("quitonload", "false").equals("true")) {
    System.exit(1);
}

Note the quotation marks; system properties are always strings.


Properties are key/value pairs, each represented by a String

if (myPropertiesObj.getProperty("quitonload").equalsIgnoreCase("true"))
{
    ...
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号