Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Need help in BufferedWriter ,why there is no value ouput to the file.txt ?

807588Apr 9 2009 — edited Apr 9 2009
Hello all,I have 2 methods inside the same class ,for some reason I couldn't output the values to the file,I am always getting result null(because the data fields are Strings) as a value when I invoke the writeToFile method,How to make this work with the real values???
The writeToFile method I found it on the internet ,Any help with explanation will be appreciated ,thank you all.

public String toString(){
this.client = "First Name: " + this.cltFirstName +"\t\t"+ "Last Name: "+this.cltLastName +"\t\t"+ "Address: " + this.cltAdd +"\t\t"+ "Date Of Birth: " + this.cltDOB +"\t\t"+ "Number Of Mortgages: " + this.mtg;

return client;
}



public void writeToFile(String filename){
BufferedWriter bufferedWriter = null;
//String printing =client;
try {

// Construct the BufferedWriter object
bufferedWriter = new BufferedWriter(new FileWriter(filename));

// Start writing to the output stream

bufferedWriter.write(toString()); // Not working ????????????????????????????????????????
bufferedWriter.newLine();


} catch (FileNotFoundException ex) {
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
} finally {

// Close the BufferedWriter
try {
if (bufferedWriter != null){
bufferedWriter.flush();
bufferedWriter.close();
}
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 7 2009
Added on Apr 9 2009
49 comments
706 views