http://xieruilin.iteye.com/blog/716031
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
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(); } } } |