how to construct properties list with defaults in java? -
this code:
import java.util.properties; public class p { public static void main(string[] args) { properties defaultproperties=new properties(); defaultproperties.put("a",1); system.out.println("default: "+defaultproperties); properties properties=new properties(defaultproperties); system.out.println("other: "+properties); } }
prints:
default: {a=1} other: {}
using java 8 in eclipse luna.
how should 1 construct properties list defaults?
the 2 problems code.
- the default properties don't work when use
get()
,put()
.
you instead need setproperty()
, 'getproperty()`.
- when print properties file, wont include default properties.
tostring()
method not sophesticated.
use instead:
properties defaultproperties=new properties(); defaultproperties.setproperty("a","s"); system.out.println("default: "+defaultproperties); properties properties=new properties(defaultproperties); system.out.println("other: "+properties.getproperty("a"));
Comments
Post a Comment