테스트 파일 변경 소스 .
How to write Java code to listen runtime changes in text file
I had a requirement to write a java code to listen continues changing text file.i have used following code to do that.
public void listenServer() throws IOException {
Reader fileReader = new FileReader("/home/chamara/server.log");
BufferedReader input = new BufferedReader(fileReader);
String line = null;
while (true) {
if ((line = input.readLine()) != null) {
System.out.println(line);
continue;
}
try {
Thread.sleep(1000L);
} catch (InterruptedException x) {
Thread.currentThread().interrupt();
break;
}
}
input.close();
return isException;
}
public void listenServer() throws IOException {
Reader fileReader = new FileReader("/home/chamara/server.log");
BufferedReader input = new BufferedReader(fileReader);
String line = null;
while (true) {
if ((line = input.readLine()) != null) {
System.out.println(line);
continue;
}
try {
Thread.sleep(1000L);
} catch (InterruptedException x) {
Thread.currentThread().interrupt();
break;
}
}
input.close();
return isException;
}
이 글은 스프링노트에서 작성되었습니다.
'JAVA' 카테고리의 다른 글
자바( 스크립트 사용 하여 리턴값 받기) (0) | 2012.05.15 |
---|---|
어트리뷰트(애플릿) (0) | 2012.05.15 |
간단 수식계산기 (0) | 2012.05.15 |
String(문자열)내의 한글 확인 (0) | 2012.05.15 |
Socket Simple 채팅 프로그램 (0) | 2012.05.15 |