4,564,684 th visitor since 2017.2.1 ( Today : 225 )
Programming
No. 315
Name. coolx
Subject. tail -f 구현한 소스
Main Cate. JSP/Servlet
Sub Cate.
Date. 2006-07-20 10:39
Hit. 7311 (220.76.115.27)
File.
이전 글에 첨부한게 확장자가 jsp 라서
볼수도 없고 다운로드도 안 되서 소스만 따로 올림.




<%@ page import='java.io.*' %>
<%@ page import='java.util.*' %>
<%
String line=null;
long newlen=0;
long length=0;


while (true)
{
RandomAccessFile contents = new RandomAccessFile("/usr/local/apache/logs/club-access_log", "r");
// do whatever with contents

newlen=contents.length();

if(length==0)
length=newlen;

if(newlen>length)
{
contents.seek(length);

while((line=contents.readLine())!=null)
{
out.println(line+"<br>");
}

length=newlen;
}

// out.println("new length : "+newlen);
out.flush();


Thread.sleep(1000);

//out.println("before : "+before+"<br>");
if(false)
break;
}
%>

[바로가기 링크] : http://coolx.net/cboard/develop/315



swindler 페이지 그냥 닫으면 file open 상태가 유지되어 문제가 발생할수 있다. 프로그램 수정이 좀더 필요하다. 2007-03-29
Name
Password
Comment
Copyright © 1999-2017, swindler. All rights reserved. 367,611 visitor ( 1999.1.8-2004.5.26 ), 2,405,771 ( -2017.01.31)

  2HLAB   2HLAB_Blog   RedToolBox   Omil   Omil_Blog