java - Trying to display created output file -


so passed file filewriter , passed printwriter. however, upon assignments instructions im supposed print these variables pass printwriter using tostring method in superclass. assignment thats why rules clear how instructors wants output be.

 system.out.print("please enter file name: ");     filename = input.next();     file fw = new file(filename + ".txt");          accountwithexception acctexception = new accountwithexception(fullname, balance, id, rate);   system.out.println(acctexception.tostring()); <---this works    // pass object printwriter , pw write file         pw = new printwriter(fw);         // print created file         pw.println(firstname);         pw.println(lastname);         pw.println(balance);         pw.println(id);         pw.println(rate);         system.out.println(pw.tostring());  <---doesn't work. prints location , im supposed somehow use overloaded tostring method output data within file (i guess after written) 

you've given own solution, need -

pw = new printwriter(fw); try {   // print created file   // pw.println(firstname);   // pw.println(lastname);   // pw.println(balance);   // pw.println(id);   // pw.println(rate);   pw.println(acctexception.tostring()); // <-- since                      // system.out.println(acctexception.tostring()); works! } {   pw.close(); // <-- close()! } 

Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -