zoukankan      html  css  js  c++  java
  • 23Properties(配置文件)

    可持久化的映射类  继承Hashtable  键和值都应该是字符串

    可持久化的意思就是可以存储在项目中,落实到本地的文件

    生成的配置文件的后缀一定是.properties,默认编码是西欧编码

     中文转不了,按u16进行编码 配置文件可以随意改动

    写入配置文件

    public class PropertiesDemo {
    
        public static void main(String[] args) throws FileNotFoundException, IOException {
            //创建对象
            Properties p=new Properties();
            //添加元素--键和值都是字符串
            p.setProperty("name","徐旺骑");
            p.setProperty("gender","女");
            p.setProperty("age", "10");
            //把要存储的内容传输到配置文件中  ---配置文件的后缀必须是.properties
            //第二个参数---文件的内容解释,就是告诉当前存入配置文件的内容做什么用的
            p.store(new FileOutputStream("p.properties"),"徐旺骑的基本信息");
            
    
        }
    
    }

    读取配置文件

    public class PropertiesDemo2 {
    public static void main(String[] args) throws FileNotFoundException, IOException {
        //创建对象
        Properties p=new Properties();
        //加载指定配置文件
        p.load(new FileInputStream("p.properties"));
        //获取配置文件的内容
        //根据键获取值
        System.out.println(p.getProperty("name"));//徐旺骑
        //根据键获取值
        System.out.println(p.getProperty("name", "丽丽"));//徐旺骑
        //列出配置文件信息
        p.list(System.out);
        /*
         * -- listing properties --
            age=10
            name=徐旺骑
            gender=女
            */
    }
    }
  • 相关阅读:
    docker stats
    Appium 环境搭建
    docker 进入容器
    Mac下Mysql启动异常["ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)"]
    python 虚拟环境--virtualenv
    visjs 绘图 图标 动态添加数据
    js 滑块登录验证
    js iframe 最顶层显示
    转化为数组
    videojs双击全屏幕观看,videojs动态加载视频
  • 原文地址:https://www.cnblogs.com/xuwangqi/p/11245138.html
Copyright © 2011-2022 走看看