最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

 更新時(shí)間:2017年03月29日 11:20:11   投稿:lqh  
這篇文章主要介紹了JSP 中Spring的Resource類讀寫中文Properties實(shí)例代碼的相關(guān)資料,需要的朋友可以參考下

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)文章

最新評(píng)論

南充市| 颍上县| 县级市| 天祝| 黄浦区| 陈巴尔虎旗| 石狮市| 平舆县| 咸丰县| 齐河县| 莱芜市| 建昌县| 托克逊县| 甘孜| 洪雅县| 安国市| 淮阳县| 津市市| 南召县| 冀州市| 贵德县| 高碑店市| 白城市| 五常市| 黔东| 营口市| 安康市| 奇台县| 龙门县| 洮南市| 同心县| 长泰县| 城固县| 海城市| 德安县| 疏附县| 麻城市| 黔西县| 循化| 且末县| 和田县|