Why print to file not working ?(here is the code..)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • redcodeheaven
    New Member
    • Nov 2008
    • 13

    Why print to file not working ?(here is the code..)

    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();
    }
    }
    }
  • dmjpro
    Top Contributor
    • Jan 2007
    • 2476

    #2
    Why two different thread for same Question? You better to post into previous one.

    Comment

    • redcodeheaven
      New Member
      • Nov 2008
      • 13

      #3
      Sorry about that.

      Yes you are right they should be in one post,my apology.

      Comment

      Working...