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

📄 weblog.java

📁 char44-2 处理web服务器的记录文件 提供了本书第4章的处理web服务器的记录文件实例的源程序;
💻 JAVA
字号:
//Weblog.java
import java.net.*;
import java.io.*;
import java.util.*;
import com.macfaq.io.SafeBufferedReader;
public class Weblog {
	public static void main(String[] args) {
		Date start = new Date( );
		try {
			//使用FileInputStream 类来装饰输入流
			FileInputStream fin = new FileInputStream(args[0]);
			Reader in = new InputStreamReader(fin);
			SafeBufferedReader bin = new SafeBufferedReader(in);
			String entry = null;
			while ((entry = bin.readLine( )) != null) {
				// 分离出IP地址
				int index = entry.indexOf(' ', 0);
				String ip = entry.substring(0, index);
				String theRest = entry.substring(index, entry.length( ));
				// 找到主机名字,并打印出来
				try {
					InetAddress address = InetAddress.getByName(ip);
					System.out.println(address.getHostName( ) + theRest);
				}
				catch (UnknownHostException e) {
					System.out.println(entry);
				}
			} // 循环终止
		}
		catch (IOException e) {
			System.out.println("Exception: " + e);
		}
		Date end = new Date( );
		long elapsedTime = (end.getTime()-start.getTime( ))/1000;
		System.out.println("Elapsed time: " + elapsedTime + " seconds");
	} // main终止
}

⌨️ 快捷键说明

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