1。使用java.util.Properties类的load()方法

示例: InputStream in = lnew BufferedInputStream(new FileInputStream(name));

Properties p = new Properties();

p.load(in);

2。使用java.util.ResourceBundle类的getBundle()方法

示例: ResourceBundle rb = ResourceBundle.getBundle(name, Locale.getDefault());

3。使用java.util.PropertyResourceBundle类的构造函数

示例: InputStream in = new BufferedInputStream(new FileInputStream(name));

ResourceBundle rb = new PropertyResourceBundle(in);

4。使用class变量的getResourceAsStream()方法

示例: InputStream in = JProperties.class.getResourceAsStream(name);

Properties p = new Properties();

p.load(in);

5。使用class.getClassLoader()所得到的java.lang.ClassLoader的getResourceAsStream()方法

示例: InputStream in = JProperties.class.getClassLoader().getResourceAsStream(name);

Properties p = new Properties();

p.load(in);

6。使用java.lang.ClassLoader类的getSystemResourceAsStream()静态方法

示例: InputStream in = ClassLoader.getSystemResourceAsStream(name);

Properties p = new Properties();

p.load(in);

补充

Servlet中可以使用javax.servlet.ServletContext的getResourceAsStream()方法

示例:InputStream in = context.getResourceAsStream(path);

Properties p = new Properties();

p.load(in);

一般文件的I/O

FileInputStream.read() //从本地文件读取二进制格式的数据

FileReader.read() //从本地文件读取字符(文本)数据

FileOutputStream.write() //保存二进制数据到本地文件

FileWriter.write() //保存字符数据到本地文件

XML文件的I/O

DocumentBuilderFactory.newDocumentBuilder().parse() //解析一个外部的XML文件,得到一个Document对象的DOM树

DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument() //初始化一棵DOM树

Document.getDocumentElement().appendChild() //为一个标签结点添加一个子结点

Document.createTextNode() //生成一个字符串结点

Node.getChildNodes() //取得某个结点的所有下一层子结点

Node.removeChild() //删除某个结点的子结点

Document.getElementsByTagName() 查找所有指定名称的标签结点

Document.getElementById() //查找指定名称的一个标签结点,如果有多个符合,则返回某一个,通常是第一个

Element.getAttribute() //取得一个标签的某个属性的的值

Element.setAttribute() //设置一个标签的某个属性的的值

Element.removeAttribute() //删除一个标签的某个属性

TransformerFactory.newInstance().newTransformer().transform() //将一棵DOM树写入到外部XML文件

读取Properties文件六种方法的更多相关文章

  1. java读取Properties文件的方法

    resource.properties的内容: com.tsinkai.ettp.name=imooc com.tsinkai.ettp.website=www.imooc.com com.tsink ...

  2. JS读取.properties文件的方法

    假设有JavaScript文件叫做:readproperties.js,这个文件需要读取config.properties这个配置文件,步骤如下: 1.  下载插件jquery.i18n.proper ...

  3. 在JavaScript文件中读取properties文件的方法

    假设有JavaScript文件叫做:readproperties.js,这个文件需要读取config.properties这个配置文件,步骤如下: 1.  下载插件jquery.i18n.proper ...

  4. Java项目中读取properties文件,以及六种获取路径的方法

    下面1-4的内容是网上收集的相关知识,总结来说,就是如下几个知识点: 最常用读取properties文件的方法 InputStream in = getClass().getResourceAsStr ...

  5. 用eclipse做项目中常遇到的问题-如何创建并读取properties文件

    在用eclipse做项目开发的时候我们常常会将一些重要的内容写在配置文件里面, 特别是连接数据库的url,username,password等信息,我们常常会新建一个properties文件将所有信息 ...

  6. 使用Properties类和ResourceBundle类读取properties文件

    一.介绍: 项目中经常把一些常用的用户名和密码都填写到一个对应的配置文件中,这样每次修改密码或者用户名的时候就可以直接修改这个配置文件了,不用动源码. 这里讲两种方式读取properties文件的方法 ...

  7. 如何通过Spring读取Properties文件

    1 在Spring中配置文件中, 配置配置文件的引用     <util:properties id="settings" location="/WEB-INF/c ...

  8. Spring 如何读取properties文件内容

    http://hi.baidu.com/alizv/blog/item/d8cb2af4094662dbf3d38539.html 在现实工作中,我们常常需要保存一些系统配置信息,大家一般都会选择配置 ...

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

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

随机推荐

  1. 云计算之路-阿里云上:SLB故障引发的网站不能正常访问

    2013年8月22日23:50~23:58左右,由于阿里云SLB(负载均衡)故障造成网站不能正常访问,给大家带来了麻烦,望大家谅解! 8月19日我们收到阿里云的短信通知: 尊敬的阿里云用户:      ...

  2. java程序main方法的参数String[] args

    public class ArgsTest { public static void main(String[] args) { System.out.println(args.length); fo ...

  3. xcode arc 下使用 block警告 Capturing [an object] strongly in this block is likely to lead to a retain cycle” in ARC-enabled code

    xcode arc 下使用 block警告 Capturing [an object] strongly in this block is likely to lead to a retain cyc ...

  4. Python中的关键字的用法

    Python有哪些关键字 -Python常用的关键字 and, del, from, not, while, as, elif, global, or, with, assert, else, if, ...

  5. ionic 隐藏header-ionic中隐藏头部header

    ionic 中隐藏头部header 通过 hide-nav-bar="true" 来实现 <ion-view hide-nav-bar="true"> ...

  6. mysql中如何统计某字段里某个字符的个数

    select * from order where length(order_num)-length(replace(order_num,'8','')) = 4

  7. Python中给文件加锁

    首先要引入库import fcntl打开一个文件f = open('./test')对该文件加密:fcntl.flock(f, fcntl.LOCK_EX)这样就对文件test加锁了,如果有其他进程要 ...

  8. Android开发——跟随手指的小球实现

      今天要实现的是一个跟随手指的小球,说白了就是让小球按着手指滑动的轨迹运动,实现起来还是比较容易的. 用到的类是drawView,我们先自定义一个DrawView组件. DrawView.java: ...

  9. UINavigationController 返回按钮去掉文字

    [[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -60) forBarMetric ...

  10. Linux I/O复用中select poll epoll模型的介绍及其优缺点的比較

    关于I/O多路复用: I/O多路复用(又被称为"事件驱动"),首先要理解的是.操作系统为你提供了一个功能.当你的某个socket可读或者可写的时候.它能够给你一个通知.这样当配合非 ...