使用J
示例
Properties p = new Properties();
p
示例
示例
ResourceBundle rb = new PropertyResourceBundle(in);
示例
Properties p = new Properties();
p
示例
Properties p = new Properties();
p
示例
Properties p = new Properties();
p
補充
Servlet中可以使用javax
示例
Properties p = new Properties();
p
完整的示例
如何上傳文件
JProperties
/**
** This program is free software
**
** You may redistribute it and/or modify it under the terms of the GNU
** General Public License as published by the Free Software Foundation
** Version
** the file LICENSE
** included with this distribution
** site at
** Free Software Foundation
**
** THIS SOFTWARE IS PROVIDED AS
** NOT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY
** OF THIS SOFTWARE
** CONSEQUENCE RESULTING FROM THE USE
** REDISTRIBUTION OF THIS SOFTWARE
**/
package com
//import javax
import java
import java
import java
import java
import java
/**
* 使用J
* User: SYNFORM
* Date:
* Time:
* To change this template use File | Settings | File Templates
*/
public class JProperties {
public final static int BY_PROPERTIES =
public final static int BY_RESOURCEBUNDLE =
public final static int BY_PROPERTYRESOURCEBUNDLE =
public final static int BY_CLASS =
public final static int BY_CLASSLOADER =
public final static int BY_SYSTEM_CLASSLOADER =
public final static Properties loadProperties(final String name
Properties p = new Properties();
InputStream in = null;
if (type == BY_PROPERTIES) {
in = new BufferedInputStream(new FileInputStream(name));
assert (in != null);
p
} else if (type == BY_RESOURCEBUNDLE) {
ResourceBundle rb = ResourceBundle
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) {
assert (JProperties
in = JProperties
assert (in != null);
p
// return new JProperties()
} else if (type == BY_CLASSLOADER) {
assert (JProperties
in = JProperties
assert (in != null);
p
// return new JProperties()
} else if (type == BY_SYSTEM_CLASSLOADER) {
in = ClassLoader
assert (in != null);
p
}
if (in != null) {
in
}
return p;
}
//
/*
public static Properties loadProperties(ServletContext context
assert (context != null);
InputStream in = context
assert (in != null);
Properties p = new Properties();
p
in
return p;
}
*/
//
/**
* ResourceBundle Adapter class
*/
public static class ResourceBundleAdapter extends Properties {
public ResourceBundleAdapter(ResourceBundle rb) {
assert (rb instanceof java
this
java
while (e
Object o = e
this
}
}
private ResourceBundle rb = null;
public ResourceBundle getBundle(String baseName) {
return ResourceBundle
}
public ResourceBundle getBundle(String baseName
return ResourceBundle
}
public ResourceBundle getBundle(String baseName
return ResourceBundle
}
public Enumeration<String> getKeys() {
return rb
}
public Locale getLocale() {
return rb
}
public Object getObject(String key) {
return rb
}
public String getString(String key) {
return rb
}
public String[] getStringArray(String key) {
return rb
}
protected Object handleGetObject(String key) {
return ((PropertyResourceBundle) rb)
}
}
}
JPropertiesTest
/**
** This program is free software
**
** You may redistribute it and/or modify it under the terms of the GNU
** General Public License as published by the Free Software Foundation
** Version
** the file LICENSE
** included with this distribution
** site at
** Free Software Foundation
**
** THIS
From:http://tw.wingwit.com/Article/program/Java/JSP/201311/19664.html