I have a class A which uses FileWriter to write in to a NotePad file.
And i have class B and class C, both creates object of class A and try to write onto the same file at same time. But only one class either class B or class C is writing into the file. But i need both the classes to write in to the file. Like i need to append to the contents of the file continuosly. you may consider like i am trying to write a log file for my application.
Help me out. regards, Surendar
Joined: Jun 09, 2003
make the FileWriter object in A, static you'll probably also need a static method to close the file
Joined: Feb 07, 2004
Hi You can try to have the following constructor method.
B and C need to use the same instance of A. Making A a singleton would be one solution, but not my preferred one.
You will likely also need to synchronize A properly.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus