通常情況下,您只需使用Vaadin標籤,無限讀取日誌文件(或直至停止)並將文件內容附加到標籤。下面是一個爲代碼不正是這樣:
Thread t = new Thread() {
@Override
public void run() {
BufferedReader reader = null;
try {
reader = new BufferedReader(new FileReader(LOGFILE));
String line;
while (running) {
line = reader.readLine();
if (line == null) {
// wait until there is more lines in the file
Thread.sleep(POLL_MS);
} else {
// append to the log Label
synchronized (MyApplication.this) {
log.setValue(log.getValue() + line + "<br />");
}
}
}
} catch (IOException e) {
// TODO: handle me
e.printStackTrace();
} catch (InterruptedException e) {
// TODO: handle me
e.printStackTrace();
} finally {
running = false;
if (reader != null) {
try {
reader.close();
} catch (IOException ignore) {
}
}
}
}
};
t.start();
對於這個工作,你需要一個"RAW" mode Label和ProgressIndicator是輪詢服務器:
ProgressIndicator pi = new ProgressIndicator();
pi.setPollingInterval(POLL_MS);
pi.setIndeterminate(true);
layout.addComponent(pi);
聲明:此代碼是從非關鍵的應用程序,例如錯誤處理和HTML轉義丟失。
來源
2012-09-10 10:26:49
eeq
謝謝,我會嘗試這個.. – LB40