This shows you the differences between two versions of the page.
javaproperty [2014/10/25 21:52] |
javaproperty [2014/10/25 21:52] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ===== Use Property in Java ===== | ||
+ | <code java> | ||
+ | import java.lang.*; | ||
+ | import java.util.*; | ||
+ | import java.io.*; | ||
+ | |||
+ | public class Prop | ||
+ | { | ||
+ | public static final String PROPERTY_FILE = "properties.config"; | ||
+ | |||
+ | public static void main(String args[]) { | ||
+ | try { | ||
+ | FileInputStream fr = new FileInputStream(new File(PROPERTY_FILE)); | ||
+ | PropertyResourceBundle prb = new PropertyResourceBundle(fr); | ||
+ | Enumeration properties = prb.getKeys(); | ||
+ | int numProperties = 0; | ||
+ | while (properties.hasMoreElements()) { | ||
+ | String key = (String) properties.nextElement(); | ||
+ | System.out.println("e="+ key + " = " + prb.handleGetObject(key)); | ||
+ | } | ||
+ | } | ||
+ | catch (FileNotFoundException e) { | ||
+ | System.err.println(e); | ||
+ | } | ||
+ | catch (IOException e) { | ||
+ | System.err.println(e); | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | </code> | ||
+ | |||
+ | ---- | ||
+ | |||
+ | * [[javainfo|Back to Java]] | ||