A friendly place for programming greenhorns!
Big Moose Saloon
Search
|
Java FAQ
|
Recent Topics
Register / Login
JavaRanch
»
Java Forums
»
Certification
»
Programmer Certification (SCJP/OCPJP)
Author
How can I use StringBuffer in this case...
Hemal Mehta
Ranch Hand
Joined: Nov 16, 2000
Posts: 101
posted
May 03, 2002 13:56:00
0
DataInputStream
dis = null;
String
textRecord = null;
try {
File f = new File("e:\\staging");
FileInputStream
fis = new
FileInputStream
(f);
BufferedInputStream
bis = new
BufferedInputStream
(fis);
dis = new
DataInputStream
(bis);
// read the first record of the database
while ( (textRecord = dis.readLine()) != null) {
}
I want to use
StringBuffer
instaed of sString to
read the above values from eachh line. How can I do that as readLine returns a String.
Corey McGlone
Ranch Hand
Joined: Dec 20, 2001
Posts: 3271
posted
May 03, 2002 13:59:00
0
Simple - just use the String that is returned by readLine as an argument to the append method of
StringBuffer
, like this:
StringBuffer buff = new StringBuffer(); while ( (textRecord = dis.readLine()) != null ) { buff.append(textRecord); }
Hope that helps,
Corey
SCJP Tipline, etc.
I agree. Here's the link:
http://ej-technologies/jprofiler
- if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
subject: How can I use StringBuffer in this case...
Similar Threads
Dynamically reading a file
writing data to CSV file
Convert file to a String
how exactly can i make out if a file in linux has just been updated or has been replaced.
DataOutputStream
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter