package com.weike.platform.util;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
public class BankErrorCodeUtil {
private static Properties properties=null;
static{
if(null==properties){
properties = new Properties();
InputStream in = null;
try {
in = BankErrorCodeUtil.class.getClassLoader().getResourceAsStream("bank-error-code.properties");
properties.load(in);
} catch (IOException e) {
e.printStackTrace();
}finally{
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
/**
* 添加错误编码
* @param key
* @param value
* @return
*/
public static boolean addErrorCode(String key,String value){
boolean flag = false;
try{
properties.put(key, value);
flag = true;
}catch(Exception e){
e.printStackTrace();
}
return flag;
}
/**
* 验证错误编码
* @param key
* @return
*/
public static boolean checkErrorCode(String key){
return properties.containsKey(key);
}
/**
* 获取错误信息
* @param key
* @return
*/
public static String getErrorText(String key){
return properties.get(key).toString();
}
}
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
public class BankErrorCodeUtil {
private static Properties properties=null;
static{
if(null==properties){
properties = new Properties();
InputStream in = null;
try {
in = BankErrorCodeUtil.class.getClassLoader().getResourceAsStream("bank-error-code.properties");
properties.load(in);
} catch (IOException e) {
e.printStackTrace();
}finally{
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
/**
* 添加错误编码
* @param key
* @param value
* @return
*/
public static boolean addErrorCode(String key,String value){
boolean flag = false;
try{
properties.put(key, value);
flag = true;
}catch(Exception e){
e.printStackTrace();
}
return flag;
}
/**
* 验证错误编码
* @param key
* @return
*/
public static boolean checkErrorCode(String key){
return properties.containsKey(key);
}
/**
* 获取错误信息
* @param key
* @return
*/
public static String getErrorText(String key){
return properties.get(key).toString();
}
}

本文介绍了一个使用Java实现的银行错误代码管理库,通过该库可以方便地添加、验证和获取错误编码。
2711

被折叠的 条评论
为什么被折叠?



