码迷,mamicode.com
首页 > Web开发 > 详细

今天 学习用到的一些知识(properties 读取,js 删除元素)

时间:2016-04-15 02:06:41      阅读:142      评论:0      收藏:0      [点我收藏+]

标签:

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

 

今天 学习用到的一些知识(properties 读取,js 删除元素)

标签:

原文地址:http://www.cnblogs.com/heibaishizhe/p/5393797.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!