Results 1 to 1 of 1
  1. #1
    ionna22's Avatar
    ionna22 is offline Member
    Join Date
    Oct 2008
    Posts
    1
    Rep Power
    0

    Default Reading growing files

    I am reading (over NFS) growing files just like tail -f does. I am using a simple code:

    Java Code:
    BufferedReader	bf = new BufferedReader(new FileReader(fileName));
    String line;
    while (true) {
      line = bf.readLine();
    
    	if (line == null) {
    		Thread.sleep(300);
    		continue;
    	}
    	else {
    	 System.out.println(line);
    	}
    }
    I noticed that when a file is growing some lines I've just read have some "bad" character in the beginning (they actually replace a "good" ones) that look like this in vi:
    ^@^@^@^@^@^@^@^@line_continues_here

    I can catch "bad" chars using:
    Java Code:
    char firstChar = line.charAt(0);
    if (Character.isISOControl(firstChar)) ....
    Same story if I am reading bytes or reading ByteBuffer via FileChannel.
    I wonder if anyone experienced the same.

    The workaround is to use RandomAccessFile, seek back N bytes and re-read them; but I still wonder what causes such behavior.
    Using: jdk1.6.0_06, RedHat 2.6.9-67, Intel(R) Xeon(R) CPU E7220 @ 2.93GHz
    Last edited by ionna22; 10-20-2008 at 06:35 PM.

Similar Threads

  1. Does OS intervene when reading Java text files
    By Tina G in forum Advanced Java
    Replies: 1
    Last Post: 04-07-2008, 03:29 PM
  2. Applet - reading text files packed into JAR file
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-08-2008, 10:15 AM
  3. Reading/Writing files through Applet
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-15-2007, 09:20 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •