file - Log monitor problem with Java and org.apache.commons.io.input.Tailer -
i trying use monitor log file , put log lines in database come in. problem having seems while thread containing tailerlistener running, cannot delete or rename log file. being case, not sure how react when log file rolls over, happens nightly. glanced @ code tailer , appears handle log rollover, can't see how when file being monitored locked.
there should no reason file cannot deleted reading it. think once file deleted/renamed throw type of exception. since tailer seems written aiming @ functionality of "tail -f".
the exact error getting when trying delete file: "this action can't completed because file open in java(tm) platform se binary"
here sample code project:
public static void main(string[] args) { // todo code application logic here file pcounter_log = new file("c:\development\temp\test.log"); try { tailerlistener listener = new pctaillistener(); tailer tailer = new tailer(pcounter_log, listener, 5000); thread thread = new thread(tailer); thread.start(); } catch (exception e) { system.out.println(e); } }
public class pctaillistener extends tailerlisteneradapter { public void handle(string line) { system.out.println(line); } }
any information on regarding tailer specificially, file handling in java, might put me on right track appreciated.
if process using file, can't delete/rename it, can read it. copy file , perform operations in copied file.
why can't modify it? because maybe there's opened stream locking file.
Comments
Post a Comment