
正文
今天 学习用到的一些知识(properties 读取,js 删除元素)
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
1.properties文件位置的关系:当properties文件放在src目录下时,编译会自动把src里的文件放到bin文件平级,因此可用this.getClass.getClassLoader.getResourceAsStream(fileName)读取,当把properties文件放到包里时,则应加相应的包路径,如:props.load(Test.class.getClassLoader().getResourceAsStream("abc.properties"));
package wang.hhtp;import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;public class PropertiesUtils
{
private static PropertiesUtils propertiesUtils=null;
private static Map<String,String> proMap=new HashMap<String,String>(); private PropertiesUtils()
{
InputStream inputStream=null;
try {
Properties pro=new Properties();
inputStream =getClass().getClassLoader().getResourceAsStream("abc.properties");
pro.load(inputStream);
Iterator ite=pro.keySet().iterator(); while(ite.hasNext()){
String key=(String) ite.next();
String value=pro.getProperty(key);
proMap.put(key, value);
}
} catch (IOException e) {
e.printStackTrace();
}finally{
try {
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
} public static PropertiesUtils getInstance(){
if(propertiesUtils ==null){
propertiesUtils=new PropertiesUtils();
}
return propertiesUtils;
} public String getValue(String key){
PropertiesUtils pro= PropertiesUtils.getInstance();
if(StringUtils.isNotBlank(key)){
String value=pro.proMap.get(key);
return value;
}
return key;
}
}
2.也可以用 static 类静态加载
class Properties{ private static Properties props = new Properties(); static {
try {
props.load(Test.class.getClassLoader().getResourceAsStream("com/abc.properties"));
} catch (Exception e) {
e.printStackTrace();
}
} public static String getProperty(String key){
return props.getProperty(key);
}
}
3.js 删除 数组某个元素
参考:http://my.oschina.net/u/2331760/blog/511439







