JSP 中Spring的Resource類讀寫中文Properties實(shí)例代碼
JSP 中Spring的Resource類讀寫中文Properties
摘要: Spring對(duì)Properties的讀取進(jìn)行了完善而全面的封裝,對(duì)于寫則仍需配合FileOutputStream進(jìn)行。
package com.oolong.common.util; import org.springframework.core.io.support.PathMatchingResourcePatternResolver; import org.springframework.core.io.support.ResourcePatternResolver; import java.io.*; import java.util.*; public class UserVar { private static String configFile = "classpath*:param.properties"; private static org.springframework.core.io.Resource resourceWritable; private static Properties p; /** * 注意事項(xiàng): * 1、properties放在source目錄下 * 2、param.properties至少有一對(duì)鍵值對(duì) */ static { p = new Properties(); org.springframework.core.io.Resource[] resources = null; try { ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); resources = resolver.getResources(configFile); if (resources != null) { for (org.springframework.core.io.Resource r : resources) { if (r != null) { p.load(r.getInputStream()); resourceWritable = r; } } } } catch (IOException e1) { e1.printStackTrace(); } } public static String get(String key) { String v = (String) p.get(key); if (v != null) { try { return new String(v.getBytes("ISO-8859-1"), "GBK"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); return null; } } return null; } public static void set(String key,String value){ if (null != resourceWritable) { try { OutputStream fos = new FileOutputStream(resourceWritable.getFile()); Properties p = new Properties(); p.load(resourceWritable.getInputStream()); value = new String(value.getBytes("GBK"),"ISO-8859-1"); p.setProperty(key, value); p.store(fos, null); fos.close(); } catch (IOException e) { e.printStackTrace(); } } } }
感謝閱讀,希望能幫助到大家,謝謝大家對(duì)本站的支持!
- Spring實(shí)戰(zhàn)之ResourceLoader接口資源加載用法示例
- Spring實(shí)戰(zhàn)之ServletContextResource訪問資源文件示例
- Spring實(shí)戰(zhàn)之FileSystemResource加載資源文件示例
- Spring實(shí)戰(zhàn)之使用ClassPathResource加載xml資源示例
- Spring實(shí)戰(zhàn)之使用@Resource配置依賴操作示例
- Spring注解@Resource和@Autowired區(qū)別對(duì)比詳解
- 詳解Spring關(guān)于@Resource注入為null解決辦法
- 詳解SpringBoot開發(fā)使用@ImportResource注解影響攔截器
- 詳解Spring注解--@Autowired、@Resource和@Service
- Spring 中 @Service 和 @Resource 注解的區(qū)別
- Spring框架中 @Autowired 和 @Resource 注解的區(qū)別
- Spring實(shí)戰(zhàn)之ResourceLoaderAware加載資源用法示例
相關(guān)文章
jsp導(dǎo)出身份證到excel時(shí)候格式不對(duì)但以X結(jié)尾的卻可以
excel導(dǎo)出身份證的時(shí)候顯示有的對(duì)有的不對(duì),身份證以X結(jié)尾的可以,其它都顯示不正確,關(guān)于這個(gè)問題的解決方法如下,需要的朋友可以參考下2014-10-10請(qǐng)求轉(zhuǎn)發(fā)jsp頁(yè)面亂碼問題的快速解決方法
下面小編就為大家?guī)硪黄?qǐng)求轉(zhuǎn)發(fā)jsp頁(yè)面亂碼問題的快速解決方法。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2016-08-08jsp+mysql數(shù)據(jù)庫(kù)操作常用方法實(shí)例總結(jié)
這篇文章主要介紹了jsp+mysql數(shù)據(jù)庫(kù)操作常用方法,以實(shí)例形式較為詳細(xì)的總結(jié)了JSP操作mysql數(shù)據(jù)庫(kù)實(shí)現(xiàn)基本的增、刪、改、查相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-10-10JSP數(shù)據(jù)庫(kù)操作例程(Use Bean)
JSP數(shù)據(jù)庫(kù)操作例程(Use Bean)...2006-10-10jsp 從web.xml讀取連接數(shù)據(jù)庫(kù)的參數(shù)
web.xml讀取連接數(shù)據(jù)庫(kù)的參數(shù),實(shí)現(xiàn)代碼。2009-05-05在JSP中使用formatNumber控制要顯示的小數(shù)位數(shù)方法
下面小編就為大家分享一篇在JSP中使用formatNumber控制要顯示的小數(shù)位數(shù)方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2017-11-11JSP中的FORM表單中只有一個(gè)input文本時(shí),按回車鍵將會(huì)自動(dòng)提交表單
這篇文章主要介紹了JSP中的FORM表單中只有一個(gè)input文本的時(shí)候,按回車鍵將會(huì)自動(dòng)將表單提交的相關(guān)資料,需要的朋友可以參考下2017-01-01