Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reading Text File

Status
Not open for further replies.

papaboy2

MIS
Jan 28, 2003
52
0
0
PH
hi, how can i read a text file and remove blank space between two lines? how can i concat the first message and second message without putting the blank space between them. thank you very much.

for example:

[Message] This my message but the next message is between blank space

Message is continued here


my code is :

BufferedReader input = null;
try {
//reads one line at a time
input = new BufferedReader( new FileReader(aFile) );
String line = null; //not declared within while loop
while (( line = input.readLine()) != null){
System.out.println(line);
}
}
catch (FileNotFoundException ex) {
ex.printStackTrace();
}
 
how can i actually check if the line doesnt contain text? if if using the buffered reader? thanks
 
Code:
 while (( line = input.readLine()) != null){
   [red]if (!line.equals(""))[/red]
     System.out.println(line);
}

--Chessbot

There is a level of Hell reserved for probability theorists in which every monkey that types on a typewriter produces a Shakespearean sonnet.
 
I would maybe hange that slightly to :

if (!line.trim().equals(""))

--------------------------------------------------
Free Database Connection Pooling Software
 
while (input.hasNextLine()) {
String name = input.nextLine();
printString(output, name);
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top