⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 readaccess.java

📁 JAVA邮件系统
💻 JAVA
字号:
import java.io.*;
import java.text.*;
import java.util.*;
public class readaccess
{
	private Vector list;
	readaccess(){
		String sFile = "c:\\access.log";//文件
		String IPAddress;//IP地址
		String VisterDate;//访问时间
		String WebPage;//所访问的页面
		String Page;
		
		list=new Vector(1000,1000);
		File file;
		file=new File(sFile);
		long length=file.length();//读出文件的长度
		 FileReader freader;//读取文件
		// 将统计文件读到 templateContents 中
 		try
 		{
  			freader = new FileReader(sFile);
 		}catch(FileNotFoundException e)
 		{
			System.out .print ("file can not read1");
 			return ;
 		}

 		char[] contents = new char[(int)length];
 		int nSize = 0;
 		try
 		{
	 		nSize = freader.read(contents,0,(int)length);
			freader.close ();
 		}catch(Exception e)
 		{
			System.out .print ("file can not read2");
 			return ;
 		}


 		String templateContents = new String(contents,0,nSize); //将文件读到字串中		
		
		//下面是用拆分法将templateContents分析成想要的数组
		
		int nBegin=0 ,nEnd=1 ,i=0;
		while(nBegin<length){
		
		
		nEnd = templateContents.indexOf("\n",nBegin);//回车
		
		if(nEnd == -1)//文件是否结束,如果结束则跳出
              	break;
		Point record;
		record=new Point();
		Page = templateContents.substring (nBegin,nEnd);
		int SubBegin=0,SubEnd;
		SubEnd=Page.indexOf("-",SubBegin);//取得IP地址
		if(SubEnd==-1)
		{nBegin=nEnd+1;
		 continue;}
		IPAddress=Page.substring(SubBegin,SubEnd);
		SubBegin=SubEnd+1;
		
		SubEnd=Page.indexOf("[",SubBegin);//取得所访问的页面的时间
		if(SubEnd==-1)
		{nBegin=nEnd+1;
		 continue;};
		SubBegin=SubEnd+1;
		SubEnd=Page.indexOf("+",SubBegin);
		if(SubEnd==-1)
		{nBegin=nEnd+1;
		 continue;};
		VisterDate=Page.substring(SubBegin,SubEnd);
		SubBegin=SubEnd+1;
		
		SubEnd=Page.indexOf("/",SubBegin);//取得所访问的页面
		if(SubEnd==-1)
		{nBegin=nEnd+1;
		 continue;};
		SubBegin=SubEnd+1;
		SubEnd=Page.indexOf("HTTP",SubBegin);
		if(SubEnd==-1)
		{nBegin=nEnd+1;
		 continue;};
		WebPage=Page.substring(SubBegin-1,SubEnd);
		SubBegin=SubEnd+1;
		nBegin=nEnd+1;
		record.Settime (VisterDate.trim());
		record.Setip (IPAddress.trim ());
		record.Setpage (WebPage.trim());
		list.addElement (record);
		}
	}
	public Vector getmessage(){
		return list;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -