1 BufferedReader br = new BufferedReader(new InputStreamReader( 2 new FileInputStream("userremain.log"))); 3 String msg = null; 4 String mail = null; 5 String newDateString=null; //用户激活后第day天的存留率,先得到那天的日期 6 //要查看的某一天的新激活用户的存留率,先获得那天的所有的用户email 7 while (true) { 8 msg = br.readLine(); 9 if (msg == null) { 10 break; // 为空文件或者是读到最后,跳出循环 11 } 12 if ("".equals(msg)) 13 continue; 14 15 // System.out.println("createTime:" + dateString); 16 if (msg.contains("createTime:"+ dateString)) { 17 mail = msg.split(" ")[0].split(":")[1]; 18 userSet.add(mail); 19 } 20 } 21 22 //用户激活后第day天的存留率,先得到那天的日期 23 newDateString=newDate(dateString, day); 24 //获得某一天新激活的用户在第day天的留存用户 25 while (true) { 26 System.out.println("1111111111111111"); 27 msg = br.readLine(); 28 if (msg == null) { 29 break; // 为空文件或者是读到最后,跳出循环 30 } 31 if ("".equals(msg)) 32 continue; 33 System.out.println("222222222222222222222"); 34 System.out.println(msg.contains("activeTime:" + newDateString)); 35 if (msg.contains("activeTime:" + newDateString)) { 36 mail = msg.split(" ")[0].split(":")[1]; 37 if(userSet.contains(mail)){ 38 userRemainSet.add(mail); 39 } 40 } 41 } 42 43 br.close();
程序运行得不到预期的结果,就在里面加入了 1111111111111111111 22222222222222222222222
结果222222222222222根本没有输出来,突然想到了《UNIX环境高级编程 》中说过的文件定位