国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 阿拉善左旗| 乌兰浩特市| 喀喇| 平舆县| 呈贡县| 临泽县| 平乐县| 井研县| 闸北区| 蒙自县| 胶南市| 中江县| 麻栗坡县| 延边| 类乌齐县| 庄浪县| 南木林县| 上饶市| 通辽市| 邯郸县| 稻城县| 永吉县| 潼关县| 岫岩| 民县| 高邑县| 尚志市| 大理市| 广平县| 昌江| 芦溪县| 肇庆市| 郁南县| 娄底市| 营山县| 彰武县| 高州市| 清原| 陕西省| 革吉县| 乌什县|