I need to write an object to a file I copied the following out of a book and put it in my program Where journeylist is the list of objects I want to save. FileOutputStream outFile=new FileOutputStream("info.dat"); ObjectOutputStream outStream = new ObjectOutputStream (outFile); outStream.writeObject (journeylist); but I get the following errors. Error : Exception java.io.FileNotFoundException must be caught, or it must be declared in the throws clause of this method. Mainmenu.java line 1213 FileOutputStream outFile=new FileOutputStream("info.dat"); Error : Exception java.io.IOException must be caught, or it must be declared in the throws clause of this method. Mainmenu.java line 1215 ObjectOutputStream outStream = new ObjectOutputStream (outFile); How do I go about solving these errors, thanks.
just do like this .. try { FileOutputStream outFile=new FileOutputStream("info.dat"); ObjectOutputStream outStream = new ObjectOutputStream (outFile); outStream.writeObject (journeylist); } catch(Exception e) {} this is a shortcut Prabhat kumar
"Reply Me", The Java Ranch has thousands of visitors every week, many with surprisingly similar names. To avoid confusion we have a naming convention, described at http://www.javaranch.com/name.jsp . We require names to have at least two words, separated by a space, and strongly recommend that you use your full real name. Please log in with a new name which meets the requirements. Thanks.