Listening changes on a text file (Unix Tail implementation with Java)
11 Comments Published November 19th, 2005 in Java Tags: .
public class Tail {
public static void main(String[] args) throws IOException {
Reader fileReader = new FileReader(args[0]);
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();
}
}
Easy enough to be posted without any comment :-)
11 Responses to “Listening changes on a text file (Unix Tail implementation with Java)”
- 1 Pingback on Feb 19th, 2010 at 18:44
Leave a Reply
Search
Calendar
| M | T | W | T | F | S | S |
|---|---|---|---|---|---|---|
| « Oct | Dec » | |||||
| 1 | 2 | 3 | 4 | 5 | 6 | |
| 7 | 8 | 9 | 10 | 11 | 12 | 13 |
| 14 | 15 | 16 | 17 | 18 | 19 | 20 |
| 21 | 22 | 23 | 24 | 25 | 26 | 27 |
| 28 | 29 | 30 | ||||
Archives
Categories
- Android (3)
- Apple (26)
- Books (7)
- Eclipse (14)
- Errors (3)
- Firefox (7)
- Git (2)
- Hardware (16)
- Horror Code (8)
- Internet (18)
- Java (98)
- JavaScript (9)
- Life, universe and everything (45)
- Lifehacks (25)
- Linux (50)
- Opinions (25)
- OSX (4)
- Python (1)
- Software (27)
- Speeches and Conferences (8)
- Unix (3)
- Web (21)
- Windows (19)
Tag Cloud
Android apple architecture Bash colors configuration CSS Development Düsseldorf Eclipse germany Git Google Hardware hdr How-To Java JAXB job junit Karmic Linux MacBook music night Open Source Opinion oracle OSX patterns Pitfalls Practices Resume Security Software Suspend TDD Testing tip tonemapped Tricks Ubuntu video Web XML
WP Cumulus Flash tag cloud by Roy Tanck and Luke Morton requires Flash Player 9 or better.
Blog License
Blogs I like
Books on the desk
Friends' Blogs
- Antonio Terreno & Valter Bernardini
- Bruno Bossola
- Daniele Galluccio
- Domenico Ventura
- Ed Schepis
- Fabrizio Gianneschi
- Luca Grulla
- Luigi Zanderighi
- Marcello Teodori
- Mida Boghetich
- Muralidharan Chandrasekaran
- Piero Ricca
- Renzo Borgatti
- Simone Bordet
- Simone Bruno
- Uberto Barbini
- Valvolog
- Webtide blogs (Greg Wilkins & Jan Bartel)
Links




















God, Have been looking everywhere for that!!!
Geeze, everyone else’s is like 100000 lines of code, i can’t believe it was that simple.
THANK YOUUUUUUU !!!!!!!
Thank you!!
exactly what I was looking for!!
great !!!
great job.
Not of any use.
It just lists the contents of the given file once and keeps on running in a loop and does not shows the new lines added to the given file.
hehehe. are you out of your mind?
Great job! This saves me a lot of time! I’ve done some little customization to this class: http://www.melandri.net/java/tail
Thank you!!!!!!!
It just simple does not work with log files rotated with log4j…I mean this code does prevent log4j from rotating !
Great post. thank you.
/Chamara Silva