package properties;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;
public class TestProperties {
public static void main(String[] args) {
Properties prop = new Properties();
prop.put("title", "the title");
prop.put("name", "the name");
try {
//保存
FileOutputStream out = new FileOutputStream("program.properties");
//为properties添加注释
prop.store(out, "the properties's comment");
out.close();
//读取
FileInputStream in = new FileInputStream("program.properties");
prop.load(in);
System.out.println(prop.getProperty("title"));
System.out.println(prop.getProperty("name"));
in.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}