java - Why the file contains only Line1 -
the generated y.txt contains line1 why line 2 abcent
public class writer{ public static void main(string[] args) { try { filewriter fw = new filewriter(new file("y.txt")); printwriter pw1 = new printwriter(fw); pw1.println ("line1 "); pw1.close(); printwriter pw2 = new printwriter(fw); pw2.println("line2 "); pw2.close(); } catch (ioexception e) { e.printstacktrace(); } } }
once close printwriter, file closed.
the javadocs printwriter.close()
state: "closes stream , releases system resources associated it. closing closed stream has no effect."
Comments
Post a Comment