Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8339643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:56:12+00:00 2026-06-09T04:56:12+00:00

may i know why i am unable to read next line in a .txt

  • 0

may i know why i am unable to read next line in a .txt file when i upload it.
it happens to all the .txt file that i try to upload and then system.out.println() with.
in my text file it contains : cats,dogs,monkey ( each in one line ) .. but the value out put is:

[Monkey][Monkey, null][Monkey, null, null][Monkey, null, null, null][Monkey, null, null, null, null][Monkey, null, null, null, null, null][Monkey, null, null, null, null, null, null]

needs help on this.
thank you.

and wondering why i can read .txt file and not .doc. need advise on this as well.

import java.awt.List;
import java.io.*;  
import java.util.ArrayList;

import javax.imageio.IIOException;
import javax.swing.JFileChooser;

public class searchforCapitalLetter {

     public static void main(String[] args) throws IOException{  


          try {  

                // file chooser
              JFileChooser chooser=new  JFileChooser();
            int returnVal = chooser.showOpenDialog(null);{
            if(returnVal == JFileChooser.APPROVE_OPTION)

            {   File f = chooser.getSelectedFile();}
            FileInputStream fin = new FileInputStream(chooser.getSelectedFile());
            DataInputStream din = new DataInputStream(fin);    
       BufferedReader br = new BufferedReader(new InputStreamReader(din)); 

    ArrayList<String>list =new ArrayList<String> ();

    if ((br.readLine()) != null) {
    while (br.readLine() != " ") {
        list.add(br.readLine());
        System.out.print (list);
    } br.close() ;
    }//closes if statement
     } // closes method dialog
                } // closes try method

         catch (FileNotFoundException e) {
                    e.printStackTrace();
                }     // closes catch method
            } // closes method body

} // closes class method
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T04:56:14+00:00Added an answer on June 9, 2026 at 4:56 am

    Per the bufferedreader api:

    public String readLine()
    throws IOException

    Reads a line of text. A line is considered to be terminated by any one of a line feed (‘\n’), a
    carriage return (‘\r’), or a carriage return followed immediately by a
    linefeed.

    Returns: A String containing the contents of the line, not including
    any line-termination characters, or null if the end of the stream has
    been reached

    Throws: IOException – If an I/O error occurs

    Note that your code is making a few errors:

    1) it is calling readline() once to check a return value and again to use the return value. The first call (in the while condition) removes the current value from the buffer, so your are dropping every other line.

    2) you are using the wrong comparison to see if there’s data remaining. x != y, where both x and y are objects, checks for pointer equality – is the memroy location where x is allocated the same as the memory location where y is allocated. what you really want is to store the value in a variable.

    For example:

    BufferedReader in = ...;
    String s = in.readLine();
    while(s!=null){
        ...
        s = in.readLine();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Some of you may know the method in Ruby that allows you to reverse
If you've used javadoc and then come to doxygen, you may know what I
Possible Duplicate: Unable to do File Upload in PHP I am trying to learn
I know this may sound silly but it seems that, my version of TortoiseSVN
Good afternoon, Many of you may already know that it is possible, for instance,
You may know this recommendation from Microsoft about the use of exceptions in .NET:
You may know the scriptaculous SlideUp effect . Well, It slides up a div
So as you may know, arrays in C# implement IList<T> , among other interfaces.
As you may know, Silverlight 3 doesn't support IMultiValueConverter and... I badly need it.
As some of you may know, use of the LIMIT keyword in MySQL does

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.