Need help in BufferedWriter ,why there is no value ouput to the file.txt ?
807588Apr 9 2009 — edited Apr 9 2009Hello 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();
}
}
}