今天 学习用到的一些知识(properties 读取,js 删除元素)
生活随笔
收集整理的這篇文章主要介紹了
今天 学习用到的一些知识(properties 读取,js 删除元素)
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
1.properties文件位置的關(guān)系:當(dāng)properties文件放在src目錄下時(shí),編譯會自動(dòng)把src里的文件放到bin文件平級,因此可用this.getClass.getClassLoader.getResourceAsStream(fileName)讀取,當(dāng)把properties文件放到包里時(shí),則應(yīng)加相應(yīng)的包路徑,如:
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;} }
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 ?類靜態(tài)加載
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 ?刪除 數(shù)組某個(gè)元素
參考:http://my.oschina.net/u/2331760/blog/511439
?
轉(zhuǎn)載于:https://www.cnblogs.com/heibaishizhe/p/5393797.html
總結(jié)
以上是生活随笔為你收集整理的今天 学习用到的一些知识(properties 读取,js 删除元素)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Springmvc整合mybatis
- 下一篇: leetcode 18 -- 4Sum