Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

stream closed with FileWriter

Status
Not open for further replies.

mgl70

Programmer
Sep 10, 2003
105
US
Hi,

I created a file by using fileWriter with true. I am able to write a string into that file. and close it. When I go again to merge my second string to the file, it is not writing basically . I got the "stream closed" exception.
I did not use any stream classes. I used a fileWriter class only. If we cannot close fileWriter object the string is not writing into the file, so we have to close the fileWriter object. if we close, how to open again?

FileWriter fw = new FileWriter(name,true); //I created this //object in different class.

I called the above object in another class.

String s= "how are you"; //here every time I am creating a //new string

fw1.write(s);
fw1.close(); //if we donot use this, the string is not //writing.

When I create another string and write into that file it is giving exception " stream closed"

How do I do this one.

thanks for your help,

 
I think if you call fw1.flush (); you will not have to close it, but if you closed it, you have to open it again.

Since there is no method 'open', you have to call the constructor again if you closed it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top