属性类loadFromXML()方法 (Properties Class loadFromXML() method)

  • loadFromXML() method is available in java.util package.

    loadFromXML()方法在java.util包中可用。

  • loadFromXML() method is used to load all the properties denoted by the XML file on the given input stream (is) into this Properties table.

    loadFromXML()方法用于将给定输入流上XML文件表示的所有属性加载到此Properties表中。

  • loadFromXML() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.

    loadFromXML()方法是一个非静态方法,只能通过类对象访问,如果尝试使用类名称访问该方法,则会收到错误消息。

  • loadFromXML() method may throw an exception at the time of loading file.

    loadFromXML()方法在加载文件时可能会引发异常。

    • IOException: This exception may throw while reading from the input stream.IOException :从输入流读取时,可能会抛出此异常。
    • InvalidPropertiesFormatException: This exception may throw when the Properties format is null exists.InvalidPropertiesFormatException :如果属性格式为null,则可能引发此异常。
    • NullPointerException: This exception may throw when the given parameter is null exists.NullPointerException :当给定参数为null时,可能引发此异常。

Syntax:

句法:

    public void loadFromXML(InputStream is);

Parameter(s):

参数:

  • InputStream is – represents the input stream to read XML file with the help of the given.

    InputStream是 –表示在给定帮助下读取XML文件的输入流。

Return value:

返回值:

The return type of the method is void, it returns nothing.

该方法的返回类型为void ,不返回任何内容。

Example:

例:

// Java program to demonstrate the example
// of void loadFromXML(InputStream is) method
// of Properties
import java.io.*;
import java.util.*;
public class StoreToXMLOfProperties {public static void main(String arg[]) throws Exception {// Instantiate Properties object
Properties prop = new Properties();
prop.put("10", "C");
prop.put("20", "C++");
prop.put("30", "JAVA");
prop.put("40", "PHP");
prop.put("50", "SFDC");
// Instantiates stream for input
// and output
FileOutputStream fos = new FileOutputStream("properties.xml");
FileInputStream is = new FileInputStream("properties.xml");
// By using storeToXML() method isto
// store the properties in the given
// XML file
prop.storeToXML(fos, null);
// By using loadFromXML() method isto
// load the properties from the given
// is stream
prop.loadFromXML(is);
// Display properties on console
prop.list(System.out);
}
}

Output

输出量

-- listing properties --
50=SFDC
40=PHP
30=JAVA
20=C++
10=C

翻译自: https://www.includehelp.com/java/properties-loadfromxml-method-with-example.aspx

Java属性loadFromXML()方法与示例相关推荐

  1. Java IOUtils.copy方法代码示例(亲测)

    本文整理汇总了Java中org.apache.commons.io.IOUtils.copy方法的典型用法代码示例.如果您正苦于以下问题:Java IOUtils.copy方法的具体用法?Java I ...

  2. Android NDK学习笔记3:JNI访问Java属性、方法

    转载请标明出处:http://blog.csdn.net/zhaoyanjun6/article/details/119209444 本文出自[赵彦军的博客] 文章目录 Java 类型和JNI符号对比 ...

  3. java user directory,Java ProcessBuilder directory()方法与示例

    语法:public File directory (); public ProcessBuilder directory (File dir); ProcessBuilder类directory()方 ...

  4. Java序列化魔术方法及其示例使用

    在上一篇文章中, 您需要了解有关Java序列化的所有知识 ,我们讨论了如何通过实现Java序列化来启用类的可序列化性. Serializable接口. 如果我们的类未实现Serializable接口, ...

  5. catalog java,Java Connection getCatalog()方法与示例

    通常,目录是一个目录,其中包含有关数据集,文件或数据库的信息.而数据库目录中包含所有数据库,基本表,视图(虚拟表),同义词,值范围,索引,用户和用户组的列表. Connection接口的getCata ...

  6. filepermission java,Java FilePermission getActions()方法与示例

    FilePermission类getActions()方法getActions()方法在java.io包中可用. getActions()方法用于检查此FilePermission和给定对象在路径名和 ...

  7. java方法参数Bundle,Java ResourceBundle keySet()方法及示例

    ResourceBundle类keySet()方法keySet()方法在java.util包中可用. keySet()方法用于从此ResourceBundle及其超级捆绑包中获取所有现有键,以在Set ...

  8. java exec waitfor,Java Process waitFor()方法与示例

    流程类waitFor()方法在java.lang包中提供了waitFor()方法. waitFor()方法用于使当前正在运行的线程在需要时等待,直到由该Process对象表示的进程完成其终止为止. 当 ...

  9. java arraylist.add(),Java ArrayList add()方法与示例

    ArrayList类add()方法 语法:public boolean add(T ele); public void add(int indices, T ele);add()方法在java.uti ...

最新文章

  1. Ubuntu 14.04下java开发环境的搭建--2--Eclipse的安装
  2. Ubuntu14.04下Mongodb数据库可视化工具安装部署步骤(图文详解)(博主推荐)
  3. 数据库 流量切分_互联网大厂有哪些分库分表的思路和技巧?
  4. 搞清axis的含义,这一篇就够了!
  5. live555源代码简介
  6. 2021内容行业研究报告
  7. [转载] python-numpy总结
  8. 对tensorflow中的tensor、placeholder及feed_dict的理解
  9. cv2不能读取中文路径
  10. 图片打散存储JAVA_通过java的i/o机制进行图片流的存储以及对网络图片的存储
  11. 格力董明珠和小米雷军的10亿赌局 --- 当年的理念谁赢谁输
  12. 【java学习记录】7.定义一个接口ArearInterface,其中包含一个方法,计算面积三角形、矩形、圆形的面积
  13. FreeRTOS的学习(二)——任务优先级问题
  14. ipad为什么显示itunes store无法连接服务器,ipad无法连接itunes store怎么办
  15. 安装gin和mod使用
  16. Html笔记——实现一组图片循环且首尾相连的滚动效果
  17. Python 第八篇:异常处理、Socket语法、SocketServer实现多并发、进程和线程、线程锁、GIL、Event、信号量、进程间通讯...
  18. Leaflet 中文api
  19. kindle运行linux命令,Kindle4: 编译并运行官方linux kernel – v2.6.31
  20. 家乐福在西班牙布局区块链,上线食品溯源平台

热门文章

  1. php 验证码文件,php实现的验证码文件类实例
  2. dnslog盲注原理
  3. jQuery数据转换与提交
  4. 修改webpack的publicPath为动态设置以适配公司活动平台
  5. SDHelper module加密系统解密
  6. 关于background-*的一些属性
  7. SQL UPDATE with INNER JOIN
  8. Sublime Text 3实用快捷键大全
  9. 检查MySQL主从数据一致性
  10. SQL Server 2005: 存储过程签名