国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 編程 > JSP > 正文

JSP 中Spring的Resource類讀寫中文Properties實(shí)例代碼

2024-09-05 00:22:57
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

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ì)本站的支持!

 

注:相關(guān)教程知識(shí)閱讀請(qǐng)移步到JSP教程頻道。
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 东丽区| 黔东| 永顺县| 白银市| 商洛市| 饶阳县| 荥经县| 团风县| 普兰县| 枞阳县| 许昌县| 冷水江市| 南丹县| 凌云县| 招远市| 涡阳县| 陵水| 百色市| 翼城县| 静宁县| 西乌珠穆沁旗| 阜南县| 库尔勒市| 乐业县| 昌江| 商都县| 鹤壁市| 黔江区| 宝清县| 永定县| 隆昌县| 报价| 富宁县| 千阳县| 宁远县| 哈巴河县| 缙云县| 呈贡县| 湘西| 诸暨市| 太仓市|