搜尋此網誌

2012年3月12日 星期一

Java Properties


 import java.io.*;  
import java.util.Properties;
public class PropertiesDemo {
/**
* File Name: some.prop
* Content : msg= Hello World.
*/
public static void main(String[] args) throws IOException {
// First you must create a file named "some.prop" then choose it .
FileInputStream fis = new FileInputStream("some.prop");
Properties prop = new Properties();
prop.load(fis); // Load properties from file input stream
String meesage = (String) prop.get("msg"); // get entry key
System.out.println(meesage);// print it out
prop.setProperty("msg", "modified Hello World");// add or modify new properties.
FileOutputStream fos = new FileOutputStream("some.prop");// Get property source file again.
prop.store(fos, "modified propery file");// Save the newest contents into the property file
prop.list(System.out);// List them out.
}
}


相關連結:
http://goodideascome.blogspot.com/2011/12/spring-ioc-with-hello-world-example.html

沒有留言:

張貼留言