0
Can we open a file in constructor of a class with BufferedWriter and write in any other function of same class?
open a file once in class as object cretaed and write it with the various function of that class
1 Answer
+ 3
Of course you can do it. But you have to make sure to close the writer when operation is finished. Create a close method for example which closes the writer and sets its reference to null. From where you use this class you have to call this close method too. To make it safer call flush often when you can.