2 mnshenyanping mnshenyanping 于 2014.07.18 19:04 提问

从文件读取数据,while循环怎么不执行呢?看了半天,求大侠解答!跪拜!

@Test
public static void readLogs()throws IOException{
Map logins=null;
Map logouts=null;
BufferedReader in =
new BufferedReader(
new InputStreamReader(
new BufferedInputStream(
new FileInputStream("out/log.txt"))));
String str;
while((str=in.readLine())!=null){
Log log = new Log(str);
System.out.println(log);
String key = log.getUser()+","+log.getPid()+","+log.getIp();
if(log.getType()==7){
logins.put(key, log);
}else if(log.getType()==8){
logouts.put(key, log);
}
}
in.close();
System.out.println("--->"+logins.toString());
System.out.println("--->"+logouts.toString());

}

1个回答

u012576250
u012576250   2014.07.19 19:21

BufferedReader in =
new BufferedReader(
new InputStreamReader(
new BufferedInputStream(
new FileInputStream("F://out//log.txt"))));
把如果是绝对路径,就把路径写全,还有要双//,一个/是转意符

mnshenyanping
mnshenyanping 路劲没有问题!我发现问题了,logins和logouts并没有new新对象,也就是没有初始化!
3 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!