package read;
import java.util.ResourceBundle;
/**
* 属性文件工厂类
* @author W
* @version V1.0
* @date 2013-4-17
*/
public interface ReadPropertiesFactory {
public ResourceBundle getErrorResource();
}
================================================
package read;
import java.util.ResourceBundle;
/**
*
* @author
* @version V1.0
* @date 2013-5-13
*/
public class ReadPropertiesFactoryImpl implements ReadPropertiesFactory {
private ResourceBundle errorResouce;
public ResourceBundle getErrorResource() {
if(errorResouce == null){
//只要读取properties的名称就可以了
errorResouce = ResourceBundle.getBundle("errorMessage");
}
return errorResouce;
}
}
===============================================
package util;
import java.io.UnsupportedEncodingException;
/**
*
* @author
* @version V1.0
* @date 2013-4-17
*/
public class StringHanlder {
public static String transformCodeIso8859Style(String code , String codeStyle) throws UnsupportedEncodingException{
return new String(code.getBytes("ISO-8859-1"),codeStyle);
}
public static String transformCodeUtf8Style(String code , String codeStyle) throws UnsupportedEncodingException{
return new String(code.getBytes("utf-8"),codeStyle);
}
}
=========================================================================
errorMessage.properties文件中的属性
E01010024=查询数据异常!
=============================================================================
package www.man.comService;
import java.util.ResourceBundle;
import read.ReadPropertiesFactoryImpl;
public class TestService {public static void main(String[] args) {
String a= TestService.getErrorValue("E01010070");System.out.println(a);}
private static ResourceBundle getErrorResource() {
ReadPropertiesFactoryImpl readPropertiesFactory =new ReadPropertiesFactoryImpl();
return readPropertiesFactory.getErrorResource();
}
public static String getErrorValue(String key){
try{
return util.StringHanlder.transformCodeIso8859Style(getErrorResource().getString(key),"utf-8");
}catch(Exception e){
e.printStackTrace();return "";
}
}}