import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
/**
* 程序即时读取日志文件
* @author RuiLin.Xie - xKF24276
*
*/
public class LogView extends Thread
{
public static void main(String[] args)
{
new LogView().start();
}
public void run()
{
//得到日志文件
FileInputStream in = null;
try
{
in = new FileInputStream("tomcat/logs/localhost_log.2010-07-19.txt");
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
byte[] b = new byte[1];
try
{
//永远试读文件是否有新数据
while(true)
{
//如果文件增加数据,则打印数据
while((in.read(b)) > 0)
{
String msg = new String(b);
System.out.print(msg);
}
}
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
程序即时读取日志文件
最新推荐文章于 2020-09-20 00:47:25 发布