/*
监视log文件变化线程
*/
class SpyThread extends java.lang.Thread{
public JTextArea jTextArea1=null;
public SpyThread(JTextArea jt){
jTextArea1=jt;
}
//是否监视文件
public static boolean spy_Loop = true;
//监视频率(毫秒)
public final static int SPY_MILLIS =1000 ;
public void run(){
while (spy_Loop){
//System.out.println(java.lang.Thread.currentThread()+Long.toString(System.currentTimeMillis()));
try{
java.lang.Thread.currentThread().sleep(SPY_MILLIS);
spyLog();
}catch(InterruptedException e){}
}
}
public void spyLog(){
String s=jTextArea1.getText();
int chars_read =0;
int size2 = 0;
try{
//根据文件名建立一个文件对象
File file = new File(SpyLogFrame.currFileName);
int size = (int)file.length();
//System.out.println(">>"+size);
//文件长度有变化
if(s.length() !=size){
//如果是文件长度增加,只动态改变增加部分
if(s.length()<size){
//原始长度
chars_read =s.length();
//增加长度
size2=size-s.length() ;
}
//否则如果是尺寸减少了,则重新刷新
else if(s.length()>=size){
chars_read =0;
size2=size;
s="";
}
}
if(size2>0||size==0){
//根据file对象建立一个input reader来读取数据
FileReader in = new FileReader(file);
//创建一个字符数组存放文件内容
char[] data = new char[size];
//从缓存中读取数据
in.read(data, 0, size);