0
点赞
收藏
分享

微信扫一扫

java.util.Properties

月半小夜曲_ 2022-02-07 阅读 160

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")
  }

}

举报

相关推荐

0 条评论