private static String getCurrName(String provinceId) {
try {
LineNumberReader lnr = new LineNumberReader(
new InputStreamReader(DataPrepareUtil.class
.getResourceAsStream("/idcard_address.txt"), "GBK"));
String line = lnr.readLine();
while (line != null) {
String[] str = line.replace(" ", "").split(" ");
int code = Integer.parseInt(StringUtils.trim(str[0]));
if (provinceId.length() == 2
&& Integer.parseInt(provinceId) * 10000 == code) {
return StringUtils.trim(str[1]);
}
if (provinceId.length() == 4
&& Integer.parseInt(provinceId) * 100 == code) {
return StringUtils.trim(str[1]);
}
if (provinceId.length() == 6
&& Integer.parseInt(provinceId) == code) {
return StringUtils.trim(str[1]);
}
line = lnr.readLine();
}
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e);
}
return null;
}
原文:http://www.cnblogs.com/anni6/p/4969420.html