2009年5月7号
根据crazycode前辈的建议修改了ReadIPInfoFileUtil。java的代码,希望更多的前辈提点。。
=================我是分割线========================
=================我是分割线========================
package g.cms.util;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* @author Jane(吴贞贞)
* @email myhongkongzhen@gmail.com
* @since JDK 1.6
* @alter 2009年5月7号
* @version 1.0 2009年4月29号
*/
public class ReadIPInfoFileUtil {
private static final Log log = LogFactory.getLog(ReadIPInfoFileUtil.class);
// private static Properties pathNameProperties = new Properties();
private static Set<String> ipInfosList = null;
static {
log.debug("IPInfo.properties loading...");
InputStream is = null;
is = ReadIPInfoFileUtil.class.getClassLoader().getResourceAsStream(
"IPInfoProperties");
// String ipInfo = pathNameProperties.get("IP0").toString();
// log.debug(ipInfo);
ipInfosList = new HashSet<String>();
try {
String ipInfoFile = System.getProperty("user.dir");
log.debug(ipInfoFile);
BufferedReader br = new BufferedReader(new InputStreamReader(is));
String ipInfo = null;
int i = 0;
do {
i++;
ipInfo = br.readLine();
if (ipInfo != null) {
ipInfo = ipInfo.trim();
/* Test Logging */
// log.debug("THIS FILE INCLUDE IP INFORMATIONS : " + i);
log.debug(ipInfo);
ipInfosList.add(ipInfo);
}
} while (ipInfo != null);
log.debug("THIS FILE INCLUDE IP INFORMATIONS : "
+ ipInfosList.size());
} catch (IOException ioe) {
log.debug("IP INFOMATION LOAD EXCEPTION !");
ioe.printStackTrace();
} finally {
try {
if (is != null) {
is.close();
is = null;
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
public static Set<String> readIPInfos() {
return ipInfosList;
}
public static void main(String[] args) {
ReadIPInfoFileUtil.readIPInfos();
}
}
=================我是分割线========================
页面排版问题没有研究明白,如果代码看的比较吃力,请下载附件看,为您带来的不便,深表歉意