java - LineNumberReader Skips the First Line of the file -


i reading first 6 lines of text file code:

file finish = new file("c:/abc statements final/");         file[] finf = finish.listfiles();         string[] filenames1 = finish.list();         linenumberreader br = null;           printwriter bw = null;           (int k = 0; k < filenames1.length; k++) {             try {             br = new linenumberreader(new filereader(new file("c:/abc statements final/" + filenames1[k])));               string line = br.readline();                while (line != null && br.getlinenumber() <= 6 ) {                    line = br.readline();                   system.err.println(line);             }                 } catch (exception asd) {                 system.err.println(asd);             } 

my output not print first line of file. knows doing wrong?

that's because you're eating first line read.

string line = br.readline();  // first line read here.  while (line != null && br.getlinenumber() <= 6 ) {        line = br.readline();  // first line overriden here.     system.err.println(line); } 

make above code this:-

string line = null;   while ((line = br.readline()) != null && br.getlinenumber() <= 6 ) {   // line read , checked - both     system.err.println(line); } 

Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -