📄 bookstat.java
字号:
package com.jb;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
public class BookStat
{
//把iparea的东西放近来
Map<String,String> ipmap=new HashMap<String ,String>();
/**
* @param args
*/
public static void main(String[] args)
{
BookStat bs=new BookStat(args);
}
public BookStat(String[] args)
{
//统计文件
statFile(args[0]);
//插入数据库
insertIntoTable();
}
private void insertIntoTable()
{
// TODO �Զ���ɷ������
}
/**
* 统计一个文件。
*/
private void statFile(String file)
{
try
{
File f = new File(file);
FileInputStream fis = new FileInputStream(f);//文件输入流
InputStreamReader isr = new InputStreamReader(fis);//读入文件
BufferedReader br = new BufferedReader(isr);//放入缓冲
String row = br.readLine();//读入行
while(row != null)//如果行不为空
{
statLine(row);//统计一个行
row = br.readLine();//读下一行
}
}
catch(Exception e)
{
System.out.println(e.toString());
}
}
/**
* ͳ��һ�м�¼��
*/
private void statLine(String row)
{
try
{
if(row == null || row.trim().length() == 0)//如果行为空或者长度为0,返回
{
return;
}
if(row.indexOf(";")==-1)
{
return ;
}
if(row.indexOf(":")==-1)
{
return ;
}
if(row.indexOf(" ")==-1)
{
return ;
}
String[] strs = row.split(" ");//�� " " �ֳ�2������
if(strs == null || strs.length != 2)
{
return;
}
//System.out.println(strs[0]);
//System.out.println(strs[1]);
String date=strs[0];
String[] hou=strs[1].split(";");
String time=hou[0];
//System.out.println("ʱ��: "+hou[0]);
String hour=time.split(":")[0];
System.out.println("Сʱ: "+hour);
String ip=hou[1];
//System.out.println("IP ��ַ: "+hou[1] +" "+ip.lastIndexOf("."));
String ip3=ip.substring(0,ip.lastIndexOf("."));
String province=checkIpArea(ip3);
// System.out.println("IP3: "+ip3);
System.out.println("ʡ��: "+new String(province.getBytes("ISO-8859-1"),"gb2312"));
String ggid=hou[2];
System.out.print ("gg id : "+hou[2]); System.out.print (hou[2].endsWith("")); System.out.println(hou[2].endsWith("null"));
String visit_id=hou[3];
System.out.println("�ο�: "+hou[3]);
String book_sort=hou[4];
System.out.println("�����: "+hou[4]);
String book_name=hou[5];
System.out.println("����: "+hou[5]);
String chpater=hou[6];
System.out.println("�½���: "+hou[6]);
String request_count=hou[7];
System.out.println("���ʴ���: "+hou[7]);
String pv=hou[8];
System.out.println("pv��: "+hou[8]);
String type=hou[9];
System.out.println("��������: "+hou[9]);
String newuseroruser=hou[10];
System.out.println("ʱ�������û�: "+hou[10]);
String online_time=hou[11];
System.out.println("����ʱ��(����): "+hou[11]);
System.out.println("\n");
}
catch(Exception e){
System.out.println(e.toString());
}
}
//����Ƿ���ƥ���ip �ҳ�ʡ��
private String checkIpArea(String ip3)
{
Connection conn = MysqlDriver.getConnection();
PreparedStatement pstmt = null;
ResultSet rst=null;
try
{
String sql="select Province from IpArea where Ip=?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, ip3);
rst=pstmt.executeQuery();
if(rst.next())
{
return rst.getString(1);
}
rst.close();
return "�й�";
}
catch (SQLException se)
{
System.out.println(se.toString());
}
finally
{
DbConnectionGrobals.closeConnection(pstmt, conn);
//System.out.println("???===");
}
return "�й�";
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -