i have the following code to retrive the data from my file. When i execute the code i come to know it’s giving only 50% of the lines from the total lines. Why it’s happening ?
public static void main(String args[]) throws IOException
{
int count = 1;
try {
FileInputStream fileInput = new FileInputStream("C:/FaceProv.log");
DataInputStream dataInput = new DataInputStream(fileInput);
InputStreamReader inputStr = new InputStreamReader(dataInput);
BufferedReader bufRead = new BufferedReader(inputStr);
while(bufRead.readLine() != null)
{
System.out.println("Count "+count+" : "+bufRead.readLine());
count++;
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
You’re reading the lines twice:
but you only count them once. So you’re actually reading the whole file, but counting only half of the lines.
Change it to:
and see what happens.