473,379 Members | 1,386 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

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

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
1 1295
Nepomuk
3,112 Expert 2GB
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

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

Similar topics

11
by: Kenneth | last post by:
I have a flat file on the server which I append to from a HTML web form. I need to delete the last line of the flat file before I append though. How do i do that? I have the following code. ...
7
by: DJP | last post by:
Hi, I need to read a file programmatically until end of file. My logic is as follows: while(!feof(Fp)) { fgets(readLine,10000,Fp);
13
by: Dan V. | last post by:
How do I create a one line text file with these control codes? e.g.: 144 = 0x90 and 147 = 0x93? I am trying to create a one line text file with these characters all one one row with no spaces. ...
2
by: CsharpGuy | last post by:
I have to read a text file and parse it out to load to a db and I'm having some issues in doing it. here is what the text file looks like Dealership number: 98665362236 Location: Maryland...
35
by: RyanS09 | last post by:
Hello- I am trying to write a snippet which will open a text file with an integer on each line. I would like to read the last integer in the file. I am currently using: file = fopen("f.txt",...
8
by: MLH | last post by:
Am trying to import 20,000+ lines of text in a file FTP'd from a UNIX platform to windows via FTP session in a DOS box. About 2000 records have multiple lines in them separated by CRLF's. ...
6
by: magix | last post by:
Hi, when I read entries in file i.e text file, how can I determine the first line and the last line ? I know the first line of entry can be filtered using counter, but how about the last line...
3
by: Ilkka Maatta | last post by:
PHP code ..... <? //Open file. $file=fopen("file.txt","r"); //read file so long when it isn't end. while (!feof($file)) { //read and print row + LF. $rivi=fgets($file,1024);
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.