• 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

Writing objects as text

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
hope you can help me im having a problem with writing objects out to a text file. I have been able to write them but not edit them as it is not recognised when I read it back in.

I know that they are in byte format, but is there a way of writing an object as text then editing it and saving it back as an object easily?

Just to let you know I only want to do this as a preliminary step to integrating the data from the object into a database.

Heres the code im usiing:
java.io.ObjectOutputStream out = new java.io.ObjectOutputStream(new java.io.FileOutputStream(file+".txt"));
out.writeObject(theQuestions);
out.close();

The object is called "theQuestions" its a vector used to hold questions I have created in a UI of different types, e.g. Multi choice, true false etc

thanks a lot in advance to anyone who can help me.....
 
Bartender
Posts: 1844
Eclipse IDE Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The best way to do this is to write the objects out as XML. There's any number of Bean-To-XML utilities out there. Try googling for XBeans.
 
anto mckeown
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks.
Yeah ive got it transfered to XML to create the test.

But I need to be able to save seperate questions and import them when needed. I thought the best way to do this was to save them to a text file then add them to a database. Then use JDBC to query the database and produce a text file with the questions you want in the test?
 
I'm thinking about a new battle cry. Maybe "Not in the face! Not in the face!" Any thoughts tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic