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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

filestream is created each time the method is called

Status
Not open for further replies.

Umamageswari

Programmer
Mar 18, 2003
7
IN
Hi all,

I have a method in a class which is called each time as and when needed. A filestream is created in the method. So when each time the method is called the filestream is created newly and so instead of appending whatever needed it is overwriting the file and atlast only the last called method is written in the file.

Here is the coding ,

package pakstream;
import paktest.*;
import java.io.*;
import java.lang.Object;
import java.io.Writer;
import java.util.*;
import java.lang.String;
public class Stream
{

public int handlestream(String[] str,Vector t) throws IOException
{
try
{
Vector temp = new Vector();
String strarr = " ";
StringBuffer sb = new StringBuffer();
System.out.println("flag" +flag);
FileOutputStream fileStream = new FileOutputStream("d:\\uma\\javacc\\javacc2.1\\samjsp\\test.cs");
ObjectOutputStream newStream = new ObjectOutputStream(fileStream);
for(int i=0;i<t.size();i++)
{
sb.append(str);
sb.append(&quot; &quot;);
}
strarr = sb.toString();
newStream.writeObject(strarr);
newStream.flush();
newStream.close();
fileStream.close();
}
catch(IOException e){System.out.println(e.getMessage());}
return str.length;
}
}

The method handlestream() is called from another package. Whenever the method is called I write something in the file.But each time the method is called a new file is created. What to do?

Pls help me in this regards. THANKZ!!!!!!!!!!!!!!!!!!!!!!!!
 
You might consider using the FileWriter class instead. It has a constructor that allows you to specify &quot;append&quot;.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top