| 发表于:2007-03-05 14:13:373楼 得分:0 |
自问自答,我写了个例子 import java.io.*; public class writelog { public static void main(string[] args) { try{ filewriter fw=new filewriter( "c:\\aa.txt ",true); bufferedwriter rf1=new bufferedwriter(fw); for (int i = 0; i < 100; i ++ ){ rf1.write( "this is line "+i); rf1.newline(); rf1.flush(); thread.sleep(1000); } rf1.close(); }catch (exception e){ system.out.println( "write error! "); } import java.io.bufferedreader; import java.io.filereader; public class readlog { public static void main(string[] args) { try{ bufferedreader rf1 = new bufferedreader(new filereader( "c:\\aa.txt ")); string s1=null; while((s1=rf1.readline())!=null){ system.out.println(s1); thread.sleep(1000); } rf1.close(); }catch (exception e){ system.out.println( "read error! "); } } } writelog是模拟连续写log内容部分, readlog 是读取不断更新的log文件部分, 先执行writelog,再执行readlog . | | |
|