• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Saving and loading????

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am writing a phonebook database and i am trying to have it save the file to the hardrive or load it from the hard drive. Any suggestions on how i can do this or any known class that can do this would be greatly appreciated.
Thanks in advance,
JavaDude.
 
Trailboss
Posts: 23990
IntelliJ IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How are you storing it in memory? How do you want to store it on disk? (as a text file?)
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have used a Properties object loaded from and stored to a file to do this successfully for a small requirement.
Properties, a subclass of Hashtable is in the java.util package. It has methods to load from an InputStream and store to an OutputStream; FileInputStream and FileOutputStream for example.
I'm not sure how scalable this would be though.

 
George Siountris
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanx for the replies,
Yes, Paul. Storing it as a text file would be nice. But, i am too new to programming to know if that is plausabile or even how you would do it. So could you please be more specific.
Thankyou,
JavaDude
 
George Siountris
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Paul Wheaton:
How are you storing it in memory? How do you want to store it on disk? (as a text file?)


Yes Paul, i would like to save it as a text file to the harddrive. How would i do this? Please be specific.
Thankyou,
JavaDude
 
paul wheaton
Trailboss
Posts: 23990
IntelliJ IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Look up readers and writers in your favorite class library reference. FileReader and FileWriter should get you started.
 
George Siountris
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Paul,
How about if i want to save it as something other than a text file. For instance if i want to save an array in memory so that i can refer back to it again for searching purposes. Would i still use FileReader and FileWriter?
Thankyou in advance,
JavaDude
 
paul wheaton
Trailboss
Posts: 23990
IntelliJ IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would then use object streams and Serializable. You would then be making the leap to "persistant objects" and what a sweet and easy leap that is!
 
I am displeased. You are no longer allowed to read this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic