By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,653 Members | 1,419 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,653 IT Pros & Developers. It's quick & easy.

Im a Java new boy, why is it i only get the last line of a text file i read in with t

P: 1
Expand|Select|Wrap|Line Numbers
  1. public class JPLCode {
  2.  
  3.     public  String detailsIn(String fileIn)
  4.     {
  5.         try
  6.         {
  7.         FileReader file = new FileReader(fileIn);
  8.         BufferedReader br=new BufferedReader (file);
  9.  
  10.         String hb = null;
  11.         String host = null;
  12.         int port = 7600;
  13.  
  14.         while ((host = br.readLine())!=null) 
  15.         hb = ("http://" +host+ ":" +port);
  16.         br.close();
  17.         return hb;
  18.  
  19.     }
  20.         catch( IOException e ) { System.out.println(e); }
  21.         return fileIn;
  22.     }
Sep 18 '13 #1
Share this Question
Share on Google+
1 Reply


Nepomuk
Expert 2.5K+
P: 3,112
Hi watermje and welcome to bytes.com!

Here, look at this piece of code:
Expand|Select|Wrap|Line Numbers
  1. while ((host = br.readLine())!=null) 
  2.     hb = ("http://" +host+ ":" +port);
This will repeat setting hb to a new value until the file ends. Then it will return the last value.

What is it exactly you were hoping to get as a result?
Sep 19 '13 #2

Post your reply

Sign in to post your reply or Sign up for a free account.