Search code examples
javaline-numbers

Difficulty while finding no of lines in a file using java?


While find out no of line in a file, it displays more number of lines.

for example in my file having only 26 line in word document. But while count using java program it displays 118.

    File f=new File("C:\\Users\\os05\\Desktop\\Venkatesan(13-02-10).doc");

    FileReader fr = new FileReader(f);

    LineNumberReader ln = new LineNumberReader(fr);

    int count = 0;

    while (ln.readLine() != null)
    {

      count++;
    }
    System.out.println("No of lines:"+count);

The above code, how is calculate the no. of line....?


Solution

  • If it is Microsoft Word Document, they are binary files, you couldn't do that way.

    You need to find appropriate api for microsoft word files.