B
beginner16
hello
1)
FileOutputStream f = new FileOutputStream ( "E:/A.txt" );
OutputStreamWriter f1 = new OutputStreamWriter ( f, "unicode" );
BufferedWriter f2 =new BufferedWriter ( f1 );
f2.write ( "seconD" );
f1.write ( "first" );
f2.close ();
a) After the above code runs, the file has words "firstseconD"
written. Why didn't code f1.write("first") overwrite characters inside
"seconD" string --> thus file would have "firstD" written in it?
b) If file A.txt existed prior to the following code, it gets deleted.
How do we prevent that?
FileOutputStream f = new FileOutputStream ( "E:/A.txt" );
2) When I write to a file and if I don't use flush() method, data
doesn't get written. I assumed that even if one doesn't use flush()
method, data eventually gets written to a file, by eventually I mean
before the program ends. But it seems that is not the case?!
thank you
1)
FileOutputStream f = new FileOutputStream ( "E:/A.txt" );
OutputStreamWriter f1 = new OutputStreamWriter ( f, "unicode" );
BufferedWriter f2 =new BufferedWriter ( f1 );
f2.write ( "seconD" );
f1.write ( "first" );
f2.close ();
a) After the above code runs, the file has words "firstseconD"
written. Why didn't code f1.write("first") overwrite characters inside
"seconD" string --> thus file would have "firstD" written in it?
b) If file A.txt existed prior to the following code, it gets deleted.
How do we prevent that?
FileOutputStream f = new FileOutputStream ( "E:/A.txt" );
2) When I write to a file and if I don't use flush() method, data
doesn't get written. I assumed that even if one doesn't use flush()
method, data eventually gets written to a file, by eventually I mean
before the program ends. But it seems that is not the case?!
thank you