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

📄 readtxt.java

📁 简单的日志分析工具
💻 JAVA
字号:
package Rd;
import java.util.*;
import java.io.*;


public class Readtxt {
	String[] dirsarr;
	String[] exedirsarr;
	
	public Readtxt(String exceptdirs,String dirs){
		this.dirsarr=dirs.split("----");
		if(exceptdirs!=""){
			this.exedirsarr=exceptdirs.split("-");
		
	    }
	}
	
	public List readall(){
		List listall=new ArrayList();
		try{
    		
	    	
	    	for (int t=0;t<this.dirsarr.length;t++){
	    		String str=this.dirsarr[t].toString();
	    		str = new String(str.getBytes("ISO-8859-1"),"gb2312");
	    		InputStream in=new FileInputStream(str);
	    		BufferedReader br = new BufferedReader(new InputStreamReader(in));
	    		String record = br.readLine();
	    		
	    		while(record != null){
	    			int bijiao=0;
	    			
	    				
	    			
	    			if(this.exedirsarr!=null){
	    				for(int y=0;y<this.exedirsarr.length;y++){
	    					 if(record.substring(0,record.length()).indexOf(this.exedirsarr[y])!=-1){
	    	                    bijiao=bijiao+1;
	    					 }
	    				 }
	    				if(bijiao==0){
	    					listall.add(record.substring(0,record.length()));
	    				}

	    			}
	    			else{
	    				listall.add(record.substring(0,record.length()));
	    			}
	    			
	    			
	    		     
	    		     record=br.readLine();
	    		}
	    		    in.close();
	    	}
	    	    
	    	}
	    	catch(Exception e){
	    		System.out.println("error");
	    	}
	    	
	    	return listall;
	}
    public List readtype(String type){
    	List typelist=new ArrayList();
    	try{
    		
    	
    	for (int t=0;t<this.dirsarr.length;t++){
    		String str=this.dirsarr[t].toString();
    		str = new String(str.getBytes("ISO-8859-1"),"gb2312");
    		InputStream in=new FileInputStream(str);
    		BufferedReader br = new BufferedReader(new InputStreamReader(in));
    		String record = br.readLine();
    		
    		while(record != null){
    			int bijiao=0;
    			if(record.substring(0,record.length()).indexOf(type)!=-1){
    				
    			
    			if(this.exedirsarr!=null){
    				for(int y=0;y<this.exedirsarr.length;y++){
    					 if(record.substring(0,record.length()).indexOf(this.exedirsarr[y])!=-1){
    	                    bijiao=bijiao+1;
    					 }
    				 }
    				if(bijiao==0){
    					typelist.add(record.substring(0,record.length()));
    				}

    			}
    			else{
    				typelist.add(record.substring(0,record.length()));
    			}
    			
    			}
    		     
    		     record=br.readLine();
    		}
    		    in.close();
    	}
    	    
    	}
    	catch(Exception e){
    		System.out.println("error");
    	}
    	
    	return typelist;
    }
    
    
    public List getEachDay(){
    	List dirlist=new ArrayList();
    	for (int i=0;i<this.dirsarr.length;i++){
    		String dirstr=this.dirsarr[i].toString().trim();
    		String[] dirarrtemp=dirstr.split("\\.");
    		String dirstrtime=dirarrtemp[1];
    	dirlist.add(dirstrtime.substring(0,dirstrtime.length()));
    	}
    	return dirlist;
    }
    public List readPm(){
    	List pmlist=new ArrayList();
    	try{
    		
    	
    	for (int t=0;t<this.dirsarr.length;t++){
    		String str=this.dirsarr[t].toString();
    		str = new String(str.getBytes("ISO-8859-1"),"gb2312");
    		InputStream in=new FileInputStream(str);
    		BufferedReader br = new BufferedReader(new InputStreamReader(in));
    		String record = br.readLine();
    		
    		while(record != null){
    			int bijiao=0;
    			if(record.substring(0,record.length()).indexOf("/pm/")!=-1 && record.substring(0,record.length()).indexOf("/fgwnw/")==-1){
    				
    			
    			if(this.exedirsarr!=null){
    				for(int y=0;y<this.exedirsarr.length;y++){
    					 if(record.substring(0,record.length()).indexOf(this.exedirsarr[y])!=-1){
    	                    bijiao=bijiao+1;
    					 }
    				 }
    				if(bijiao==0){
    					pmlist.add(record.substring(0,record.length()));
    				}

    			}
    			else{
    				pmlist.add(record.substring(0,record.length()));
    			}
    			
    			}
    		     
    		     record=br.readLine();
    		}
    		    in.close();
    	}
    	   
    	}
    	catch(Exception e){
    		System.out.println("error");
    	}
    	
    	return pmlist;
    }
    
    public List readelse(){
    	List elselist=new ArrayList();
    	try{
    		
    	
    	for (int t=0;t<this.dirsarr.length;t++){
    		String str=this.dirsarr[t].toString();
    		str = new String(str.getBytes("ISO-8859-1"),"gb2312");
    		InputStream in=new FileInputStream(str);
    		BufferedReader br = new BufferedReader(new InputStreamReader(in));
    		String record = br.readLine();
    		
    		while(record != null){
    			int bijiao=0;
    			String temp=record.substring(0,record.length());
    			if(temp.indexOf("/fgwnw/xxzl")==-1 && temp.indexOf("/fgwnw/xtdw")==-1
    	    			   && temp.indexOf("/fgwnw/wgzdt")==-1 && temp.indexOf("/fgwnw/pfw")==-1
    	    			   && temp.indexOf("/fgwnw/mryw")==-1 && temp.indexOf("/pm/")==-1
    	    			   && temp.indexOf("/fgwnw/ddjs")==-1){
    				
    			
    			if(this.exedirsarr!=null){
    				for(int y=0;y<this.exedirsarr.length;y++){
    					 if(record.substring(0,record.length()).indexOf(this.exedirsarr[y])!=-1){
    	                    bijiao=bijiao+1;
    					 }
    				 }
    				if(bijiao==0){
    					elselist.add(record.substring(0,record.length()));
    				}

    			}
    			else{
    				elselist.add(record.substring(0,record.length()));
    			}
    			
    			}
    		     
    		     record=br.readLine();
    		}
    		    in.close();
    	}
    	   
    	}
    	catch(Exception e){
    		System.out.println("error");
    	}
    	
    	return elselist;
    }
    
    public List readpic(){
    	List piclist=new ArrayList();
    	try{
    		
    	
    	for (int t=0;t<this.dirsarr.length;t++){
    		String str=this.dirsarr[t].toString();
    		str = new String(str.getBytes("ISO-8859-1"),"gb2312");
    		InputStream in=new FileInputStream(str);
    		BufferedReader br = new BufferedReader(new InputStreamReader(in));
    		String record = br.readLine();
    		
    		while(record != null){
    			int bijiao=0;
    			String temp=record.substring(0,record.length());
    			if(temp.indexOf(".gif")!=-1 || temp.indexOf(".jpg")!=-1 || temp.indexOf(".swf")!=-1 || temp.indexOf(".png")!=-1){
    				
    			
    			if(this.exedirsarr!=null){
    				for(int y=0;y<this.exedirsarr.length;y++){
    					 if(record.substring(0,record.length()).indexOf(this.exedirsarr[y])!=-1){
    	                    bijiao=bijiao+1;
    					 }
    				 }
    				if(bijiao==0){
    					piclist.add(record.substring(0,record.length()));
    				}

    			}
    			else{
    				piclist.add(record.substring(0,record.length()));
    			}
    			
    			}
    		     
    		     record=br.readLine();
    		}
    		    in.close();
    	}
    	    
    	}
    	catch(Exception e){
    		System.out.println("error");
    	}
    	
    	return piclist;
    }
    
    public List readip(){
    	List iplist=new ArrayList();
    	try{
    		
    	
    	for (int t=0;t<this.dirsarr.length;t++){
    		String str=this.dirsarr[t].toString();
    		str = new String(str.getBytes("ISO-8859-1"),"gb2312");
    		InputStream in=new FileInputStream(str);
    		BufferedReader br = new BufferedReader(new InputStreamReader(in));
    		String record = br.readLine();
    		
    		while(record != null){
    			int bijiao=0;
    			String temp=record.substring(0,record.length());

    				
    			
    			if(this.exedirsarr!=null){
    				for(int y=0;y<this.exedirsarr.length;y++){
    					 if(record.substring(0,record.length()).indexOf(this.exedirsarr[y])!=-1){
    	                    bijiao=bijiao+1;
    					 }
    				 }
    				if(bijiao==0){
    					iplist.add(record.substring(0,record.length()));
    				}

    			}
    			else{
    				iplist.add(record.substring(0,record.length()));
    			}
    			
    			
    		     
    		     record=br.readLine();
    		}
    		    in.close();
    	}
    	    Collections.sort(iplist);
    	}
    	catch(Exception e){
    		System.out.println("error");
    	}
    	
    	return iplist;
    }
    
    
    
    /*public static void main(String args[]){
    	String dirs="d:/record/localhost_access_log.2008-04-08.txt----d:/record/localhost_access_log.2008-04-09.txt----";
    	String exceptdirs="";
    	Readtxt rt=new Readtxt(exceptdirs,dirs);
    	List typelist=rt.readtype("/fgwnw/wgzdt");
    	for (int i=0;i<typelist.size();i++){
    		
    		System.out.println(typelist.get(i).toString());
    	}
    }*/
}

⌨️ 快捷键说明

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