Search code examples
javabufferedreadernamed-pipes

Java BufferedReader miss some values


I have problem with BufferedReader.

My source code works fine, but the problem is when I read a value from named pipe it missed some values.

delim="\t";
reader = new BufferedReader(new FileReader("/tmp/base.pip"));
while ((line = reader.readLine())!=null) {
            try{
             timestamp = Long.parseLong(line.split(delim)[0]);
            }
            catch(Exception e){
                continue;
            }

I need to read whole line to get first column value properly.

example

original line : 12345678 A B

readed line: 2345678 A B (missed first bit)

Is there any suggestion to solve this problem?

p.s it works fine, but only a few lines have problem like the above examples.


Solution

  • I've tested your program and it works fine on my computer.

    1. Check your delim String delim = "\t"
    2. Check your file and it has a tab seperator between them.
    3. Check the line value in your program.

    If you don't have a tab space, consider using a regular expression which accepts any number of spaces.

    String delim = "\\s+";
    

    delim = '\t'

    Split cannot take a character as a delimiter. Please check that. It has to be delim = "\t"