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 = Bundle(name, Default());
3。使用java.util.PropertyResourceBundle类的构造函数img2img是什么意思
示例: InputStream in = new BufferedInputStream(new FileInputStream(name));
ResourceBundle rb = new PropertyResourceBundle(in);
4。使用class变量的getResourceAsStream()方法
示例: InputStream in = ResourceAsStream(name);
Properties p = new Properties();
p.load(in);
5。使用ClassLoader()所得到的java.lang.ClassLoader的getResourceAsStream()方法
示例: InputStream in = ClassLoader().getResourceAsStream(name);
Properties p = new Properties();
p.load(in);
6。使用java.lang.ClassLoader类的getSystemResourceAsStream()静态方法
systempause用法 示例: InputStream in = SystemResourceAsStream(name);
Properties p = new Properties();
p.load(in);
补充
Servlet中可以使用javax.servlet.ServletContext的getResourceAsStream()方法
示例:InputStream in = ResourceAsStream(path);表格concatenate函数加入破折号
Properties p = new Properties();
p.load(in);
JProperties.java文件
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 Properties loadProperties(final String name, final int type) throws IOException {
Properties p = new Properties();
InputStream in = null;
if (type == BY_PROPERTIES) {
in = new BufferedInputStream(new FileInputStream(name));
assert (in != null);
p.load(in);
} else if (type == BY_RESOURCEBUNDLE) {
ResourceBundle rb = Bundle(name, Default());
assert (rb != null);
p = new ResourceBundleAdapter(rb);
} else if (type == BY_PROPERTYRESOURCEBUNDLE) {
in = new BufferedInputStream(new FileInputStream(name));
assert (in != null);
ResourceBundle rb = new PropertyResourceBundle(in);
p = new ResourceBundleAdapter(rb);
} else if (type == BY_CLASS) {
plc基础知识课件 assert (JProperties.class.equals(new JProperties().getClass()));
in = ResourceAsStream(name);
assert (in != null);
程序员培训班价格 p.load(in);
// return new JProperties().getClass().get
ResourceAsStream(name);
} else if (type == BY_CLASSLOADER) {
assert (ClassLoader().equals(new JProperties().getClass().getClassLoader()));
in = ClassLoader().getResourceAsStream(name);
assert (in != null);
p.load(in);
// return new JProperties().getClass().getClassLoader().getResourceAsStream(name);
} else if (type == BY_SYSTEM_CLASSLOADER) {
in = SystemResourceAsStream(name);
assert (in != null);
p.load(in);
}
if (in != null) {
in.close();
}
return p;
}
// ---------------------------------------------- servlet used
// ---------------------------------------------- support class
public static class ResourceBundleAdapter extends Properties {
public ResourceBundleAdapter(ResourceBundle rb) {
assert (rb instanceof java.util.PropertyResourceBundle);
this.rb = rb;
java.util.Enumeration e = rb.getKeys();
while (e.hasMoreElements()) {
Object o = e.nextElement();
this.put(o, rb.getObject((String) o));
}
}
private ResourceBundle rb = null;
public ResourceBundle getBundle(String baseName) {
Bundle(baseName);
properties是什么文件 }
public ResourceBundle getBundle(String baseName, Locale locale) {
Bundle(baseName, locale);
}
public ResourceBundle getBundle(String baseName, Locale locale, ClassLoader loader) {
Bundle(baseName, locale, loader);
}
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论