I am having problems using an ObjectInputStream to read from a file. My program uses a File to check whether or not a specific file exists. If it exists my program will attempt to create a FileInputStream for the file and associate an ObjectInputStream with it. It should first read an int, then start reading objects. For some reason it returns an I/O error whenever I attempt to run it.

The file itself is created by using a FileOutputStream and associating an ObjectOutputStream with it. I then write an int and my objects follow that. Any ideas what my problem could be?

File checkFile = new File("test.tst");
		ObjectInputStream readFile = new ObjetInputStream(new FileInputStream("test.tst");
		int bushels = readFile.readInt();
		BlueBerry firstObject = (BlueBerry) readFile.readObject();
		BlueBerry secondObject = (BlueBerry) readFile.readObject();

The test.tst file is written in such a way that it matches this reading format. If anyone can see an error in how this works I would appreciate it or any sample code I could reference! Thanks!

9 Years
Discussion Span
Last Post by dmanw100

It already does but thanks! I'm assuming that integers can be mixed in the same file as other objects. Is there another way to save that I could try?

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.