public static void record(Message message)//Message is a class
{
try
{
BufferedOutputStream buf=new BufferedOutputStream(new FileOutputStream("E:/kruthika/proj/a.bin"));
byte[] b =serializer.serialize(message);
buf.write(b);
buf.flush();
}
catch(Exception e){System.out.print(e);}
}
this is a small code which serializes my message object(this object contains some text message) and writes it to a binary file. This works perfectly if the object carries only one word for a text but if many words are sent, obviously it is overwritten in the binary file. So how do i alter the snippet to create multiple files dynamically and then store different message in different file?
you can either pass the fileName-parameter to the function or use a static counter or the current datetime as filename:
shown is the solution with a counter