当前位置: 首页 > news >正文

网站色彩心理centos7 wordpress网站

网站色彩心理,centos7 wordpress网站,山东省建设执业资格注册中心网站,wordpress单页怎么加留言文章目录 概述常见方法写入读取遍历 概述 Properties 继承于 Hashtable。表示一个持久的属性集#xff0c;属性列表以key-value的形式存在#xff0c;key和value都是字符串。 Properties 类被许多Java类使用。例如#xff0c;在获取环境变量时它就作为System.getPropertie… 文章目录 概述常见方法写入读取遍历 概述 Properties 继承于 Hashtable。表示一个持久的属性集属性列表以key-value的形式存在key和value都是字符串。 Properties 类被许多Java类使用。例如在获取环境变量时它就作为System.getProperties()方法的返回值。 我们在很多需要避免硬编码的应用场景下需要使用properties文件来加载程序需要的配置信息比如 JDBC、MyBatis框架等。Properties类则是properties文件和程序的中间桥梁不论是从properties文件读取信息还是写入信息到properties文件都要经由Properties类。 常见方法 除了从Hashtable中所定义的方法Properties定义了以下方法 String getProperty(String key)用指定的键在此属性列表中搜索属性。String getProperty(String key,String defaultPproperty)用指定的键在属性列表中搜索属性。void list(PrintStream streamOut)将属性列表输出到指定的输出流。void list(PrintWriter streamOut)将属性列表输出到指定的输出流。voi load(InputStream streamIn) throws IOException从输入流中读取属性列表键和元素对。Enumeration propertyNames()按简单的面向行的格式从输入字符流中读取属性列表键和元素Object setProperty(String key, String value)调用Hashtable的方法putvoid store(OutputStream streamOut, String description)以适合使用load(InputStream)方法加载到Properties表中的格式将此Properties表中的属性列表键和元素写入输出流。 Properties类 下面我们从写入、读取、遍历等角度来解析Properties类的常见用法 写入 Properties类调用setProperty方法将键值对保存到内存中此时可以通过getProperty方法读取propertyNames方法进行遍历但是并没有将键值对持久化到属性文件中故需要调用store方法持久化键值对到属性文件中。 package cn.htl;import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.Date; import java.util.Enumeration; import java.util.Properties; import junit.framework.TestCase;public class PropertiesTester extends TestCase {public void writeProperties() {Properties properties new Properties();OutputStream output null;try {output new FileOutputStream(config.properties);properties.setProperty(url, jdbc:mysql://localhost:3306/);properties.setProperty(username, root);properties.setProperty(password, root);properties.setProperty(database, users);//保存键值对到内存properties.store(output, Steven1997 modify newDate().toString());// 保存键值对到文件中} catch (IOException io) {io.printStackTrace();} finally {if (output ! null) {try {output.close();} catch (IOException e) {e.printStackTrace();}}}} }读取 下面给出常见的六种读取properties文件的方式 package cn.htl;import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.util.Locale; import java.util.Properties; import java.util.PropertyResourceBundle; import java.util.ResourceBundle;/** * 读取properties文件的方式 * */ public class LoadPropertiesFileUtil {private static String basePath src/main/java/cn/habitdiary/prop.properties;private static String path ;/*** 一、 使用java.util.Properties类的load(InputStream in)方法加载properties文件** return*/public static String getPath1() {try {InputStream in new BufferedInputStream(new FileInputStream(new File(basePath)));Properties prop new Properties();prop.load(in);path prop.getProperty(path);} catch (FileNotFoundException e) {System.out.println(properties文件路径书写有误请检查);e.printStackTrace();} catch (IOException e) {e.printStackTrace();}return path;}/*** 二、 使用java.util.ResourceBundle类的getBundle()方法* 注意这个getBundle()方法的参数只能写成包路径properties文件名否则将抛异常** return*/public static String getPath2() {ResourceBundle rb ResourceBundle.getBundle(cn/habitdiary/prop);path rb.getString(path);return path;}/*** 三、 使用java.util.PropertyResourceBundle类的构造函数** return*/public static String getPath3() {InputStream in;try {in new BufferedInputStream(new FileInputStream(basePath));ResourceBundle rb new PropertyResourceBundle(in);path rb.getString(path);} catch (FileNotFoundException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (IOException e) {e.printStackTrace();}return path;}/*** 四、 使用class变量的getResourceAsStream()方法* 注意getResourceAsStream()方法的参数按格式写到包路径properties文件名.后缀** return*/public static String getPath4() {InputStream in LoadPropertiesFileUtil.class.getResourceAsStream(cn/habitdiary/prop.properties);Properties p new Properties();try {p.load(in);path p.getProperty(path);} catch (IOException e) {e.printStackTrace();}return path; }/*** 五、* 使用class.getClassLoader()所得到的java.lang.ClassLoader的* getResourceAsStream()方法* getResourceAsStream(name)方法的参数必须是包路径文件名.后缀* 否则会报空指针异常* return*/public static String getPath5() {InputStream in LoadPropertiesFileUtil.class.getClassLoader().getResourceAsStream(cn/habitdiary/prop.properties);Properties p new Properties();try {p.load(in);path p.getProperty(path);} catch (IOException e) {e.printStackTrace();}return path;}/*** 六、 使用java.lang.ClassLoader类的getSystemResourceAsStream()静态方法* getSystemResourceAsStream()方法的参数格式也是有固定要求的** return*/public static String getPath6() {InputStream in ClassLoader.getSystemResourceAsStream(cn/habitdiary/prop.properties);Properties p new Properties();try {p.load(in);path p.getProperty(path);} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}return path;}public static void main(String[] args) {System.out.println(LoadPropertiesFileUtil.getPath1());System.out.println(LoadPropertiesFileUtil.getPath2());System.out.println(LoadPropertiesFileUtil.getPath3());System.out.println(LoadPropertiesFileUtil.getPath4());System.out.println(LoadPropertiesFileUtil.getPath5());System.out.println(LoadPropertiesFileUtil.getPath6());}}其中第一、四、五、六种方式都是先获得文件的输入流然后通过Properties类的load(InputStreaminStream)方法加载到Properties对象中最后通过Properties对象来操作文件内容。 第二、三中方式是通过ResourceBundle类来加载Properties文件然后ResourceBundle对象来操做properties文件内容。 其中最重要的就是每种方式加载文件时文件的路径需要按照方法的定义的格式来加载否则会抛出各种异常比如空指针异常。 遍历 下面给出四种遍历Properties中的所有键值对的方法 /** * 输出properties的key和value */ public static void printProp(Properties properties) {System.out.println(---------方式一------------);for (String key : properties.stringPropertyNames()) {System.out.println(key properties.getProperty(key));}System.out.println(---------方式二------------);SetObject keys properties.keySet();//返回属性key的集合for (Object key : keys) {System.out.println(key.toString() properties.get(key));}System.out.println(---------方式三------------);SetMap.EntryObject, Object entrySet properties.entrySet();//返回的属性键值对实体for (Map.EntryObject, Object entry : entrySet) {System.out.println(entry.getKey() entry.getValue());}System.out.println(---------方式四------------);Enumeration? e properties.propertyNames();while (e.hasMoreElements()) {String key (String) e.nextElement();String value properties.getProperty(key);System.out.println(key value);} }
http://www.hkea.cn/news/14578497/

相关文章:

  • 做网站图片格式建筑设计集团
  • 江山做网站视觉传达设计培训机构有哪些
  • 广州网站设计公司排名门户网站建设工作会议
  • 大连网站运营制作方案怎么注册网站挣流量
  • yy怎么一直在模板相关信息圆柱钢模板优势是什么?企业网站建设模板和定制化有什么区别呢?拼命加载中做直播网站多少钱
  • 广州网站开发定制设计建网站买完域名后怎么做
  • 天津百度整站优化服务动漫制作专业有本科吗
  • 网站定制要花多少钱财经网站建设
  • 做网站 哪些公司安庆网站建设公司简
  • 泰安高新区建设局网站做国外网站衣服码数要怎么写
  • 建立什么网站深圳网站维护
  • 建设商务网站过程功能性的网站归档系统
  • 家装网站建设公司泰安人才网首页
  • win7 做网站服务器优化是什么梗
  • 手机网站推荐几个seo怎么优化步骤
  • 网站一般都是用什么软件做的微信小程序开发工具下载哪个版本
  • 开发一个网站 要多久pc端网站开发
  • 软件工程做项目网站深圳建网站公司哪家好
  • 河南网站建设首选公司镇江教育云平台网站建设
  • 华为免费企业网站建设大良网站建设机构
  • 网站前端切图做多个页面网站资源整合与建设
  • 网站建设市场分析提升关键词排名有哪些方法
  • 不要网站域名旧房翻新装修多少钱一平方
  • 东莞网站推广运营公司免费网站推广网站破解版
  • 大连里程科技做网站做暧暧小视频有声音的网站
  • 西安高端网站开发广州做护肤品的网站
  • 湖州建设局投标网站网站功能列表
  • 网站开发价格预算做音响的是哪个网站
  • 提高自己网站深圳龙华观澜网站建设公司
  • 开发网站需要什么人员高碑店住房和城乡建设局网站