java.util.Properties

java.util.Properties类

import java.io.{FileInputStream, FileOutputStream}
import java.util.Properties

object Properties {
  def main(args: Array[String]): Unit = {
    
    val props: Properties =new Properties()
    val stream: FileInputStream =new FileInputStream("sample.properties")
  
    //读取配置文件
    props.load(stream)
    props.list(System.out)
    //设置key
    props.setProperty("name","Tom")
    //获取value
    println(props.getProperty("log4j.rootCategory"))
    println(props.getProperty("pwd"))
    
    //配置输出
    props.store(new FileOutputStream("properties.properties"), "stores")
    props.storeToXML(new FileOutputStream("properties.xml"), "storeToXML")
  }

}

上一篇:JDBC连接Mysql报错.... WARN: Establishing SSL connection without server‘s identit....


下一篇:Spring注解之@PropertySource注解加载配置文件的属性