Java属性loadFromXML()方法与示例
属性类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()方法与示例相关推荐
- Java IOUtils.copy方法代码示例(亲测)
本文整理汇总了Java中org.apache.commons.io.IOUtils.copy方法的典型用法代码示例.如果您正苦于以下问题:Java IOUtils.copy方法的具体用法?Java I ...
- Android NDK学习笔记3:JNI访问Java属性、方法
转载请标明出处:http://blog.csdn.net/zhaoyanjun6/article/details/119209444 本文出自[赵彦军的博客] 文章目录 Java 类型和JNI符号对比 ...
- java user directory,Java ProcessBuilder directory()方法与示例
语法:public File directory (); public ProcessBuilder directory (File dir); ProcessBuilder类directory()方 ...
- Java序列化魔术方法及其示例使用
在上一篇文章中, 您需要了解有关Java序列化的所有知识 ,我们讨论了如何通过实现Java序列化来启用类的可序列化性. Serializable接口. 如果我们的类未实现Serializable接口, ...
- catalog java,Java Connection getCatalog()方法与示例
通常,目录是一个目录,其中包含有关数据集,文件或数据库的信息.而数据库目录中包含所有数据库,基本表,视图(虚拟表),同义词,值范围,索引,用户和用户组的列表. Connection接口的getCata ...
- filepermission java,Java FilePermission getActions()方法与示例
FilePermission类getActions()方法getActions()方法在java.io包中可用. getActions()方法用于检查此FilePermission和给定对象在路径名和 ...
- java方法参数Bundle,Java ResourceBundle keySet()方法及示例
ResourceBundle类keySet()方法keySet()方法在java.util包中可用. keySet()方法用于从此ResourceBundle及其超级捆绑包中获取所有现有键,以在Set ...
- java exec waitfor,Java Process waitFor()方法与示例
流程类waitFor()方法在java.lang包中提供了waitFor()方法. waitFor()方法用于使当前正在运行的线程在需要时等待,直到由该Process对象表示的进程完成其终止为止. 当 ...
- java arraylist.add(),Java ArrayList add()方法与示例
ArrayList类add()方法 语法:public boolean add(T ele); public void add(int indices, T ele);add()方法在java.uti ...
最新文章
- Ubuntu 14.04下java开发环境的搭建--2--Eclipse的安装
- Ubuntu14.04下Mongodb数据库可视化工具安装部署步骤(图文详解)(博主推荐)
- 数据库 流量切分_互联网大厂有哪些分库分表的思路和技巧?
- 搞清axis的含义,这一篇就够了!
- live555源代码简介
- 2021内容行业研究报告
- [转载] python-numpy总结
- 对tensorflow中的tensor、placeholder及feed_dict的理解
- cv2不能读取中文路径
- 图片打散存储JAVA_通过java的i/o机制进行图片流的存储以及对网络图片的存储
- 格力董明珠和小米雷军的10亿赌局 --- 当年的理念谁赢谁输
- 【java学习记录】7.定义一个接口ArearInterface,其中包含一个方法,计算面积三角形、矩形、圆形的面积
- FreeRTOS的学习(二)——任务优先级问题
- ipad为什么显示itunes store无法连接服务器,ipad无法连接itunes store怎么办
- 安装gin和mod使用
- Html笔记——实现一组图片循环且首尾相连的滚动效果
- Python 第八篇:异常处理、Socket语法、SocketServer实现多并发、进程和线程、线程锁、GIL、Event、信号量、进程间通讯...
- Leaflet 中文api
- kindle运行linux命令,Kindle4: 编译并运行官方linux kernel – v2.6.31
- 家乐福在西班牙布局区块链,上线食品溯源平台