Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

While loop to read lines in text file, reads one, skips one

807580Feb 21 2010 — edited Feb 21 2010
Hello guys,

I have a problem with this while loop to get it read every line in the text file. Now it read one and skips one,
basically reads odd lines, skips even ones. I want to read every line in the file.
I use it to insert data in a table in a database.
       FileInputStream fstream = new FileInputStream("nations.txt");
    // Get the object of DataInputStream
	DataInputStream in = new DataInputStream(fstream);
        BufferedReader br = new BufferedReader(new InputStreamReader(in));
        String strLine;

while ((strLine = br.readLine()) != null)   {
		String delimiter = ",";
      StringTokenizer st = new StringTokenizer(strLine,delimiter);			
		String code = st.nextToken();
		String name = st.nextToken();
				
		stmt.executeUpdate("INSERT INTO nat VALUES('"+ code +"'"+delimiter+"'"+ name +"')");		
       // read the next line
       strLine = br.readLine();					
    }
    //Close the input stream
    in.close();
Any help will be greatly appreciated.
Thank you in advance.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 21 2010
Added on Feb 21 2010
6 comments
1,475 views