Created
November 20, 2013 09:04
-
-
Save alghanmi/7560028 to your computer and use it in GitHub Desktop.
Java Properties Files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.io.FileInputStream; | |
| import java.io.IOException; | |
| import java.util.Properties; | |
| public class PropertiesDemo { | |
| PropertiesDemo() { | |
| } | |
| //Print Properties | |
| public void showProperties(Properties props) { | |
| for(String key : props.stringPropertyNames()) { | |
| String val = props.getProperty(key); | |
| System.out.println("Key: '" + key + "' val: '" + val + "'"); | |
| } | |
| } | |
| public static void main(String args[]) { | |
| PropertiesDemo pd = new PropertiesDemo(); | |
| Properties props = new Properties(); | |
| try { | |
| FileInputStream in = new FileInputStream("propFile.properties"); | |
| props.load(in); | |
| in.close(); | |
| } catch(IOException e) { | |
| e.printStackTrace(); | |
| } catch(IllegalArgumentException iae) { | |
| iae.printStackTrace(); | |
| } | |
| pd.showProperties(props); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #Sample Key-Value pairs | |
| a:propA | |
| b:propB | |
| c:propC | |
| #Add multi lines and space | |
| d : another Property | |
| e : multi\nline\nproperty | |
| #Also, use equal sign instead of colon | |
| f = fProp | |
| g = gProp |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment