Umamageswari
Programmer
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(" "
}
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!!!!!!!!!!!!!!!!!!!!!!!!
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(" "
}
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!!!!!!!!!!!!!!!!!!!!!!!!