I have a file called "objects.txt" which contains some serializable objects.
I want to write some objects to the file.
Is there a way to check if the objects I want to write to the file already exist in the file before writing? Would it be better to not check even if the objects already exist in the file?
Below is example of writing object to file:
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import javax.swing.JFrame;
public class WriteObjectsDemo {
public static void main(String[] args)
{
try(FileOutputStream f = new FileOutputStream("objects.txt"))
{
ObjectOutputStream o = new ObjectOutputStream(f);
// Write objects to file
JFrame j = new JFrame();
o.writeObject(j);
}
catch (IOException e)
{
e.printStackTrace();
}
}
}