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

Popular posts from this blog

javascript - How to synchronize the Three.js and HTML/SVG coordinate systems (especially w.r.t. the y-axis)? -

javascript - How do I find how many occurences are there of a highlighted string, and which occurence is it? -

java - Reading data from multiple zip files and combining them to one -