Properties类的load方法
我们先看一下load方法的源码:
public synchronized void load(InputStream inStream) throws IOException {load0(new LineReader(inStream));}
传入了一个输入流,然后调用了load0方法。
再看一下load0方法:
private void load0 (LineReader lr) throws IOException {char[] convtBuf = new char[1024];int limit;int keyLen;int valueStart;char c;boolean hasSep;boolean precedingBackslash;while ((limit = lr.readLine()) >= 0) {c = 0;keyLen = 0;valueStart = limit;hasSep = false;//System.out.println("line=<" + new String(lineBuf, 0, limit) + ">");precedingBackslash = false;while (keyLen < limit) {c = lr.lineBuf[keyLen];//need check if escaped.if ((c == '=' || c == ':') && !precedingBackslash) {valueStart = keyLen + 1;hasSep = true;break;} else if ((c == ' ' || c == '\t' || c == '\f') && !precedingBackslash) {valueStart = keyLen + 1;break;}if (c == '\\') {precedingBackslash = !precedingBackslash;} else {precedingBackslash = false;}keyLen++;}while (valueStart < limit) {c = lr.lineBuf[valueStart];if (c != ' ' && c != '\t' && c != '\f') {if (!hasSep && (c == '=' || c == ':')) {hasSep = true;} else {break;}}valueStart++;}String key = loadConvert(lr.lineBuf, 0, keyLen, convtBuf);String value = loadConvert(lr.lineBuf, valueStart, limit - valueStart, convtBuf);put(key, value);}}
看起来非常长,但是我们也不需要一字一句的看,直接看最后面。
我们都知道,Properties是Map的子类,看最后一句用到了put方法就明白了。
load0方法其实就是逐行读取properties配置文件,分隔成两个字符串key和value,将他们放进Properties对象中。
后面如果需要用到这些值,直接调用Properties对象就可以了。
Properties类的load方法相关推荐
- 为什么properties中没有load方法_为什么游戏戒不掉?或许你没有找对正确方法
文|子安· 编辑|涓涓 <地下城勇士>,简称DNF,又到周年庆了,它已经火了12年了,这是游戏史上的一个奇迹.从巅峰时期的800万勇士,到现在的100级,它熬死了<龙之谷>.& ...
- 为什么properties中没有load方法_用“维生素E”可以美白淡斑,为什么多数没有效果?原来方法不对...
很多的女性都是特别爱美的,所以都希望自己的脸可以白白嫩嫩的,在很多的情况下,很多人都特别喜欢用一些昂贵的化妆品或者是护肤品之类的,但是其实在现实生活当中,就有一些东西可以护肤美白,我们今天要说的就是, ...
- java properties读取缓存_java 读取 properties文件的各种方法
1.使用java.util.Properties类的load()方法 示例: InputStream in = lnew BufferedInputStream(new FileInputStream ...
- 使用J2SE API读取Properties文件的六种方法(选择自 kindani 的 Blog )
使用J2SE API读取Properties文件的六种方法 1.使用java.util.Properties类的load()方法 示例: InputStream in = lnew BufferedI ...
- java properties $_Java读取Properties文件的六种方法
1.使用java.util.Properties类的load()方法 示例: InputStream in = lnew BufferedInputStream(new FileInputStream ...
- Java读取Properties文件的六种方法
1.使用java.util.Properties类的load()方法 示例: InputStream in = lnew BufferedInputStream(new FileInputStream ...
- java读取propertiesshib_Java读取Properties文件的六种方法
使用J2SE API读取Properties文件的六种方法 1.使用java.util.Properties类的load()方法 示例: InputStream in = lnew BufferedI ...
- java读取properties文件_Java读取Properties文件的六种方法
Java读取Properties文件有以下六种方法: 1.使用java.util.Properties类的load()方法String fileName="E:/system.propert ...
- [Java基础] Properties类的基本操作和介绍
引言 Java中的.properties文件是一种配置文件,主要用于表达配置信息:通俗来说,存放的数据就像是Map中的key和value的对应关系一样:这样就可以通过键值对来对属性进行匹配,并且属性列 ...
最新文章
- RFID读写器Impinj R420开发C#
- 详解Oracle介质恢复的内部过程
- Linq To Sql中实现Left Join与Inner Join使用Linq语法与lambda表达式
- LC_ALL=C的含义
- 空间mysql升级_MySQL升级的3种方法
- 数据库知识:SQLServer变量相关知识介绍
- Android TextView多行文本滚动实现
- php 执行 load database,phpcms实用的pc_base::load调用方法解析
- Atitit orm优缺点 Hinaernate mybatis 区别。attilax总结
- SecureCrt中文破解版直接下载使用免破解免安装并解决中文乱码问题
- python语言def_python中def的含义
- 数字信号处理2-截止频率
- MAC 无法重启或关机
- 如何在安卓手机上面远程桌面操作
- [PC] 微软账号连接不上
- 小米 无线 linux 鼠标,实测小米便携式鼠标2:小巧精致 支持无线双模连接
- 《调色师手册:电影和视频调色专业技法(第2版)》——调色所需的其他硬件...
- 在Linux下如何查CC攻击
- 电子邮件礼仪(E-Mail Etiquette)
- T80 Google云端AI实验室