For a class assignment, I'm required to write an object to a file. Our professor gave us a section of code to complete this, but apparently it's wrong because I'm getting an error. Here's my code.
class InvMaintenance {
//create an OutputStream to write data to a file
FileOutputStream fos = new FileOutputStream(inven.dat);
BufferedOutputStream bos = new BufferedOutputStream(fos);
ObjectOutputStream oos = new ObjectOutputStream(bos);
final long MAX_SIZE = 100; //constant for array length
Inventory cInventory = new Inventory(MAX_SIZE); //instantiate Inventory object
oos.writeObject(cInventory); //write initial Inventory to file
public static void main(String[] args) {
//Output options
/* Inventory Maintenance
1) Add Item
2) Remove Item
3) Sell Item
4) Receive Item
5) Display Inventory
6) Quit
Please Select NUMBER: */
//switch on options
//call appropriate method
oos.writeObject(cInventory);
oos.close();
}
}
My error is occuring on the line oos.writeObject(cInventory);
Item.java:150: <identifier> expected
oos.writeObject(cInventory); //write initial Inventory to file
^
Item.java:150: <identifier> expected
oos.writeObject(cInventory); //write initial Inventory to file
^
2 errors
And yes, for some reason it's saying this is two separate errors that are... exactly the same.
Any help debugging would be appreciated. What's wrong?