import java.io.*;
public class IO{
public static void main(
String args[]) throws IOException{
File f = new File("doom.txt");
PrintWriter k = new PrintWriter(f);
PrintWriter p = new PrintWriter(f);
p.println("bazinga ");
k.println(" we are even ");
p.write("yes i did");
p.close();
k.close();
BufferedReader fr = new BufferedReader(new FileReader(f));
System.out.print(fr.readLine());
}
}
case 1: In this problem when the sequence of line 5 & 6 changed then the output become
output:
we are even
But if we remove ln from println at line 8 thenoutput become
output:
we are even i did
when we remove ln from line 7 & 8 then output become
output:
we are even did
as @Tina Smith said when two writers are associated with a single file,
the second writer to be flushed overwrites the first writer. so in this case the file doom.txt should contain "we are even" i.e true for case 1.
but when we are removing ln from println then both object comes into picture so file contain changed , and the content is not understandable by me . what actually happening with this sort of code can anyone make me understand.