我们先看一下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方法相关推荐

  1. 为什么properties中没有load方法_为什么游戏戒不掉?或许你没有找对正确方法

    文|子安· 编辑|涓涓 <地下城勇士>,简称DNF,又到周年庆了,它已经火了12年了,这是游戏史上的一个奇迹.从巅峰时期的800万勇士,到现在的100级,它熬死了<龙之谷>.& ...

  2. 为什么properties中没有load方法_用“维生素E”可以美白淡斑,为什么多数没有效果?原来方法不对...

    很多的女性都是特别爱美的,所以都希望自己的脸可以白白嫩嫩的,在很多的情况下,很多人都特别喜欢用一些昂贵的化妆品或者是护肤品之类的,但是其实在现实生活当中,就有一些东西可以护肤美白,我们今天要说的就是, ...

  3. java properties读取缓存_java 读取 properties文件的各种方法

    1.使用java.util.Properties类的load()方法 示例: InputStream in = lnew BufferedInputStream(new FileInputStream ...

  4. 使用J2SE API读取Properties文件的六种方法(选择自 kindani 的 Blog )

    使用J2SE API读取Properties文件的六种方法 1.使用java.util.Properties类的load()方法 示例: InputStream in = lnew BufferedI ...

  5. java properties $_Java读取Properties文件的六种方法

    1.使用java.util.Properties类的load()方法 示例: InputStream in = lnew BufferedInputStream(new FileInputStream ...

  6. Java读取Properties文件的六种方法

    1.使用java.util.Properties类的load()方法 示例: InputStream in = lnew BufferedInputStream(new FileInputStream ...

  7. java读取propertiesshib_Java读取Properties文件的六种方法

    使用J2SE API读取Properties文件的六种方法 1.使用java.util.Properties类的load()方法 示例: InputStream in = lnew BufferedI ...

  8. java读取properties文件_Java读取Properties文件的六种方法

    Java读取Properties文件有以下六种方法: 1.使用java.util.Properties类的load()方法String fileName="E:/system.propert ...

  9. [Java基础] Properties类的基本操作和介绍

    引言 Java中的.properties文件是一种配置文件,主要用于表达配置信息:通俗来说,存放的数据就像是Map中的key和value的对应关系一样:这样就可以通过键值对来对属性进行匹配,并且属性列 ...

最新文章

  1. RFID读写器Impinj R420开发C#
  2. 详解Oracle介质恢复的内部过程
  3. Linq To Sql中实现Left Join与Inner Join使用Linq语法与lambda表达式
  4. LC_ALL=C的含义
  5. 空间mysql升级_MySQL升级的3种方法
  6. 数据库知识:SQLServer变量相关知识介绍
  7. Android TextView多行文本滚动实现
  8. php 执行 load database,phpcms实用的pc_base::load调用方法解析
  9. Atitit orm优缺点 Hinaernate mybatis 区别。attilax总结
  10. SecureCrt中文破解版直接下载使用免破解免安装并解决中文乱码问题
  11. python语言def_python中def的含义
  12. 数字信号处理2-截止频率
  13. MAC 无法重启或关机
  14. 如何在安卓手机上面远程桌面操作
  15. [PC] 微软账号连接不上
  16. 小米 无线 linux 鼠标,实测小米便携式鼠标2:小巧精致 支持无线双模连接
  17. 《调色师手册:电影和视频调色专业技法(第2版)》——调色所需的其他硬件...
  18. 在Linux下如何查CC攻击
  19. 电子邮件礼仪(E-Mail Etiquette)
  20. T80 Google云端AI实验室

热门文章

  1. Live800在线客服系统:客户体验即是业绩来源
  2. MapServer教程2
  3. 为什么国内的软件很臃肿,而且还没有国外的发达?
  4. 解决轮播动态加图片效果失效的问题
  5. Pytorch 混合精度训练(Automatic Mixed Precision)原理解析
  6. Android SDK 离线包安装
  7. png格式图片背景不透明问题解决
  8. 合肥市2023年度高校毕业生“双千培养工程”培训项目学员招募公告
  9. 计算机英语forward,英语forward是什么中文意思
  10. 【译】GraalVM—下一代JVM介绍