|
-
October 11th, 2004, 04:51 PM
#1
Senior Member
readLine(), skipping a line
Hello guys!!!
The following the code for reading, and printing the lines if the file "fil1.txt".
---------------------------------------------------------
import java.io.*;
class ReadOne
{
public static void main(String[] args)throws IOException
{
FileReader f1 = new FileReader("c:\\test\\fil1.txt");
BufferedReader file = new BufferedReader(f1);
String text;
int i=0;
while(file.readLine()!= null)
{
text=file.readLine();
i++;
System.out.println(text);
}
System.out.println("\n The value of I is: "+i);
file.close();
}
}
---------------------------------------
The problem is that the file "fil1.txt" has 12 lines and this code is only showing 6 lines. i.e. it is skipping every alternate line.
the contents of the file are the followiing, so that u can try and guide me, about the problem.
----------------------------------------------------------------------
1 we we we f sd s d s d
2 da f sd fs df dsf ds f dsf ds f sf
3 dfsdf fs f d f dsf s df sd fs
4 fdgrsre ff ef fe f ffef a fdsf
5 fr erew325 4aw3234 wer 43r 2
6 rwr43rwerr 23r 3r 2r2 r d s et uyj yu
7 tyryttru u76iyuy jyju yjty
8 errt45ft45tw4e g54t 45g 45y 5y rewyt 65y wy y
9 243t45645 t yhgre y 65 y 4t 45yt 4w t4
10 35 wr43 t 4 4t 45 4 gt45 t
11 34tr3 r4 t45 t45 t 54y 45
12 er 43f3 g4 4 g
-----------------------------------------------------------------
Any sort of help will be appreciated.
U get What U pay for. 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|