Writing output from console in java to text file -
i'd show console's output in text file.
public static void main(string [ ] args){ datafilter df = new datafilter(); df.displaycategorizedlist(); printstream out; try { out = new printstream(new fileoutputstream("c:\\test1.txt", true)); system.setout(out); } catch (filenotfoundexception e) { // todo auto-generated catch block e.printstacktrace(); } }
i result correctly on screen not result in textfile ? test file genereted empty??
you should print "console" after have set system output stream file.
datafilter df = new datafilter(); printstream out; try { out = new printstream(new fileoutputstream("c:\\test1.txt", true)); system.setout(out); df.displaycategorizedlist(); } catch (filenotfoundexception e) { // todo auto-generated catch block e.printstacktrace(); } { if (out != null) out.close(); }
also use block close stream otherwise data might not flushed file.
Comments
Post a Comment