• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Basic help for a basic person

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks
 
Sheriff
Posts: 7001
6
Eclipse IDE Python C++ Debian Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
You learn how to close your eyes and tell yourself "this just isn't really happening to me." Tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic