Java读取Properties文件的六种方法
Java读取Properties文件的六种方法
Java读取properties文件
使用J2SE API读取Properties文件的六种方法
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);
完整的示例,可以参考附件文件
如何上传文件,谁知道请告诉以下。 只好把source都贴上来了
JProperties.java文件
package com.kindani;
//import javax.servlet.ServletContext;
import java.util.*;
import java.io.InputStream;
import java.io.IOException;
import java.io.BufferedInputStream;
import java.io.FileInputStream;
public class JProperties {
public final static int BY_PROPERTIES = 1;
public final static int BY_RESOURCEBUNDLE = 2;
public final static int BY_PROPERTYRESOURCEBUNDLE = 3;
public final static int BY_CLASS = 4;
public final static int BY_CLASSLOADER = 5;
public final static int BY_SYSTEM_CLASSLOADER = 6;
public final static Propertie
相关文档:
今天碰到一个很有意思的问题,就是关于使用LinkedList作为HashMap或者Hashtable得key,但是最后发现数据并没有存进去。
首先说一下HashMap,Hashtable吧,它们都继承了Cloneable, Map, Serializable。它们两个基本上是一样的,“The HashMap
class is roughly equivalent to Hashtable
, except that it is
unsy ......
package com.tiantian;
import java.util.*;
public class JAVAContainer {
public static void main(String[] args) throws Exception {
// ArrayList
{
&nb ......
在这里总结一下抽取word,pdf的几种方法。
很多人用java进行文档操作时经常会遇到一个问题,就是如何获得word,excel,pdf等文档的内容?我研究了一下,在这里总结一下抽取word,pdf的几种方法。
1. 用jacob
其实jacob是一个bridage,连接java和com或者win32函数的一个中间件,jacob并不 ......
注:wait notify 都是Object的方法
同步(阻塞) :是一种防止对共享资源访问导致的数据不一致的一种模式。
详细请参看操作系统。
在Java中,由于对多线程的支持,对同步的控制主要通过以下几个方法,synchronized,和wait(),notify()和notifyAll(),下面进行一一的讲解:
A关键字synchronized
每个java对 ......