package com.abs.sample;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Properties;
public class T001UsePropertiesFile {
public static void UpdateProperties() throws IOException {
Properties propertie = new Properties();
FileInputStream inputFile = new FileInputStream("src//SystemInfo.properties");
propertie.load(inputFile);
inputFile.close();
OutputStream fos = new FileOutputStream("src//SystemInfo.properties");
propertie.setProperty("SystemPort", "22333") ;
propertie.store(fos, "update SystemPort to 22333");
}
public static void ReadProperties() throws IOException {
Properties propertie = new Properties();
FileInputStream inputFile = new FileInputStream("src//SystemInfo.properties");
propertie.load(inputFile);
inputFile.close();
if(propertie.containsKey("SystemPort")){
System.out.println("SystemPort : "+propertie.getProperty("SystemPort"));//得到某一属性的值
}
else {
System.out.println("Not found parm SystemAddr ") ;
}
}
public static void main(String[] args) throws IOException {
//
UpdateProperties() ;
ReadProperties() ;
//
}
}