import java.io.*; class File1 { public static void main(String A[]) { try { BufferedWriter fout=new BufferedWriter(new FileWriter("d:\\Test.txt",true)); fout.write('A'); } catch(Exception e) { System.err.println(e); } } } The file gets created but it's an empty(0 byte)file. The character 'A' should be there. Why it's not there????
data is not shown because u didn't close the file. Write fout.close(); after the write opertaion is performed on a file..........:happy:
Why dont i need to call close() on FileOutputStream object??? Why is it mandatory to close() on BufferedWriter object???? More precisely, the following code works fine but the code in my 1st post does not work correctly. Why.....?????????? Code: import java.io.*; class File1 { public static void main(String A[]) { try { //BufferedWriter fout=new BufferedWriter(new FileWriter("d:\\Usrdtls.bsk",true)); FileOutputStream fout= new FileOutputStream("d:\\Usrdtls.bsk"); fout.write(65); //fout.close(); } catch(Exception e) { System.err.println(e); } } }
Right now I have got few questions. Let the 1st one be answered first and then accordingly I'll ask the other questions. "Buffering characters is way to provide, the efficient reading or writing of characters, arrays, and lines." - Would you please elaborate on this "efficiency"..I mean how is it efficient??? Please, help me understand with a suitable example...!!!
Right now I have got few questions. Let the 1st one be answered first and then accordingly I'll ask the other questions. "Buffering characters is way to provide, the efficient reading or writing of characters, arrays, and lines." - Would you please elaborate on this "efficiency"..I mean how is it efficient??? Please, help me understand with a suitable example...!!!
I have already read that and also the documentation for BufferedReader. From there only, this question of mine cropped up....about inefficiency. I need little more clarifications on it..... 1. If I'm buffering it, then what exactly is happening when we call print() each time???? (Please, answer this one first and then I have other questions to ask also. I will ask accordingly). Ref: http://download.oracle.com/javase/1,5.0/docs/api/java/io/InputStreamReader.html http://download.oracle.com/javase/1,5.0/docs/api/java/io/BufferedReader.html