• Post Reply Bookmark Topic Watch Topic
  • New Topic

Basic help for a basic person

 
Reply Me
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
prabhat kumar
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!