苏州画廊网站建设,如何提高用户和网站的互动性,广东米可信息技术有限公司,微信网站是怎么做的文章目录前言一、Properties类的使用 :1、创建sk.properties文件2、编写读取 properties 属性文件#xff0c;并输出属性值。3、运行结果总结前言
Properties类的介绍 : 在Java中提供了 java.util.Properties 类#xff0c;来读取 .properties 属性文件。在程序调用 Propert…
文章目录前言一、Properties类的使用 :1、创建sk.properties文件2、编写读取 properties 属性文件并输出属性值。3、运行结果总结前言
Properties类的介绍 : 在Java中提供了 java.util.Properties 类来读取 .properties 属性文件。在程序调用 Properties 类的 load() 方法时系统把 .properties 属性文件的内容加载到内存中。因为 Properties 类继承了 Hashtable 类Properties 类把“”之间的内容添加到Hashtable 对象的 key 值并同时添加 key 值对应的 value 值也就是“”右侧的值。所有在编写 .properties 属性文件时一定要用“”号把名称与值分隔开。 通过 .properties 属性文形式只能保存 String 类型信息。 Properties 类是线程安全的多个线程可以共享一个Properties对象而不需要外部同步。 Properties官方api 一、Properties类的使用 :
1、创建sk.properties文件
在项目的默认路径src目录下创建 sk.properties 属性文件名称可以自定义扩展名必须为 properties 。
nameJack
gendermale2、编写读取 properties 属性文件并输出属性值。
//从配置文件获取密钥信息private static final Properties properties getProperties();private static String getProperties(){Properties properties new Properties();try {//生产环境根目录properties.load(new FileInputStream(System.getProperty(user.dir).concat(/sk.properties)));//本地测试
// properties.load(new FileInputStream((src/main/resources/sk.properties)));} catch (IOException e) {e.printStackTrace();}return properties.getProperty(vehLocationPartitions);}public void test(){String nameproperties.getProperty(name);String genderproperties.getProperty(gender);// 输出结果System.out.println(name: name);System.out.println(gender: gender);}3、运行结果
name: Jack gender: male 总结 如果此篇文章有帮助到您, 希望打大佬们能关注、点赞、收藏、评论支持一波非常感谢大家 如果有不对的地方请指正!!! 参考1 参考2