• 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

ObjectContainer - serialized objects

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey, I need a little help with a project (my code below). I need to write an ObjectContainer class which implements interface Container, it's task is to write and read serialized objects to disk.
Object has to be saved to the disk and acquire unique ID (int) to retrieve it. ID is returned to the user.
Additional Info: System is supposed to handle more than 1 objetct, I can't modify Container interface.
My main problem is that I don't know how make each object to be written to a different file (maybe also different directory).
I commented out some ideas i've tried.

 
Ranch Hand
Posts: 123
Firefox Browser Spring Tomcat Server
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Unless it is not allowed, the perfect solution is to use the unique ID as the file name. Use any prefix that you want, like '.obj' or whatever. For example, your folder will have '0000000001.obj', and '0000000002.obj' which implies that you have 2 objects on the disk, and also 2 corresponding entries in your Map.

You will use that unique ID, of course, to form the filename, and thereby able to find and load the file on the disk.
 
Jann Kowalski
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for a suggestions, I've changed my code a bit, and my main problem now is how to use some iterator or just loop to handle many objects and increment ID.

 
Kathleen Angeles
Ranch Hand
Posts: 123
Firefox Browser Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
my suggestion included adding a filename to the path. the path is a folder. what you want is create a file, not a folder. the filename to be added to the path is partially or fully, the String value of the unique id.

what you are doing now is correct, except that you are directly saving and reading the path itself, which is a folder. you should write or read 'a file', not a folder.

example, path is 'c:/'. if id is 1, add like,'1.obj' to the path, making it 'c:/1.obj'.
 
Jann Kowalski
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
problem solved, thanks for help:)
 
reply
    Bookmark Topic Watch Topic
  • New Topic