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???
Any help with explanation will be appreciated ,thank you all.
public String toString(){
this.client = "First Name: " + this.cltFirstNa me +"\t\t"+ "Last Name: "+this.cltLastN ame +"\t\t"+ "Address: " + this.cltAdd +"\t\t"+ "Date Of Birth: " + this.cltDOB +"\t\t"+ "Number Of Mortgages: " + this.mtg;
return client;
}
public void writeToFile(Str ing filename){
BufferedWriter bufferedWriter = null;
//String printing =client;
try {
// Construct the BufferedWriter object
bufferedWriter = new BufferedWriter( new FileWriter(file name));
// Start writing to the output stream
bufferedWriter. write(toString( )); // Not working ????????
bufferedWriter. newLine();
} catch (FileNotFoundEx ception ex) {
ex.printStackTr ace();
} catch (IOException ex) {
ex.printStackTr ace();
} finally {
// Close the BufferedWriter
try {
if (bufferedWriter != null){
bufferedWriter. flush();
bufferedWriter. close();
}
} catch (IOException ex) {
ex.printStackTr ace();
}
}
}
Any help with explanation will be appreciated ,thank you all.
public String toString(){
this.client = "First Name: " + this.cltFirstNa me +"\t\t"+ "Last Name: "+this.cltLastN ame +"\t\t"+ "Address: " + this.cltAdd +"\t\t"+ "Date Of Birth: " + this.cltDOB +"\t\t"+ "Number Of Mortgages: " + this.mtg;
return client;
}
public void writeToFile(Str ing filename){
BufferedWriter bufferedWriter = null;
//String printing =client;
try {
// Construct the BufferedWriter object
bufferedWriter = new BufferedWriter( new FileWriter(file name));
// Start writing to the output stream
bufferedWriter. write(toString( )); // Not working ????????
bufferedWriter. newLine();
} catch (FileNotFoundEx ception ex) {
ex.printStackTr ace();
} catch (IOException ex) {
ex.printStackTr ace();
} finally {
// Close the BufferedWriter
try {
if (bufferedWriter != null){
bufferedWriter. flush();
bufferedWriter. close();
}
} catch (IOException ex) {
ex.printStackTr ace();
}
}
}
Comment