我想在weblogic寫入日誌時使用java讀取weblogic日誌文件(緩衝),但我只想讀取當我啓動時存在的內容閱讀它。Java IO - 在其他應用程序寫入時讀取大文件
我該怎麼做?
public class DemoReader implements Runnable{
public void run() {
File f = new File ("c:\\test.txt");
long length = f.length();
long readedBytes = 0;
System.out.println(length);
try {
BufferedReader fr = new BufferedReader(new FileReader(f));
String line = "";
while((line = fr.readLine()) != null && readedBytes < length){
readedBytes += line.getBytes().length;
if(readedBytes > length){
break;
}else{
System.out.println(line);
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
複製文件並從中讀取。完成。 :) – karim79 2010-11-26 11:17:41
增加了一些演示代碼 – 2010-11-26 16:31:47