java.util.Properties

2022/2/7 17:13:20

本文主要是介绍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")
  }

}



这篇关于java.util.Properties的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程