일부 로그 파일을 꼬리/구문 분석하려고합니다. 날짜로 시작하는 항목은 여러 행으로 확장 될 수 있습니다.Java 스캐너가 파일을 따르지 않습니다
이 방법은 작동하지만 새로운 파일을 볼 수는 없습니다.
File inputFile = new File("C:/test.txt");
InputStream is = new FileInputStream(inputFile);
InputStream bis = new BufferedInputStream(is);
//bis.skip(inputFile.length());
Scanner src = new Scanner(bis);
src.useDelimiter("\n2010-05-01 ");
while (true) {
while(src.hasNext()){
System.out.println("[ " + src.next() + " ]");
}
}
)는 (스캐너의 다음() 또는 hasNext처럼 보일 파일에 새 항목을 감지하지 않습니다.
내가 어떻게 구현할 수 있는지, 기본적으로 사용자 정의 구분 기호가있는 꼬리 -f가 있습니다.
확인 - 내가 스캐너를 새로 고침 &을 확인하고있어 켈리의 조언을 사용하여이 작동합니다. 고맙습니다 !!
누군가에게 개선 제안이있는 경우 plz do!
File inputFile = new File("C:/test.txt");
InputStream is = new FileInputStream(inputFile);
InputStream bis = new BufferedInputStream(is);
//bis.skip(inputFile.length());
Scanner src = new Scanner(bis);
src.useDelimiter("\n2010-05-01 ");
while (true) {
while(src.hasNext()){
System.out.println("[ " + src.next() + " ]");
}
Thread.sleep(50);
if(bis.available() > 0){
src = new Scanner(bis);
src.useDelimiter("\n2010-05-01 ");
}
}
지금은 어떤 일이 발생합니까? 예외가 발생하거나 새로운 데이터를 감지하지 않고 무한 루프에 걸립니까? –
새로운 데이터를 감지하지 않고 무한 루프. 그것을 여러 가지 방법으로 시도해 보았습니다. hasNext() first, buffered/unbuffered .. –