• 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
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

read a file content of serialized object

 
Ranch Hand
Posts: 607
11
Android Python Open BSD VI Editor Slackware
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI I would like to syout on the console a line of a serialized object in this example I would like to have as output 80 20 in the console
( the code is not real efficient because I played around with an example of the book head first java


( please how can i put the scroll to my code? cannot see any option to do it thanks)

 
author
Posts: 23958
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Giovanni Montano wrote:HI I would like to syout on the console a line of a serialized object in this example I would like to have as output 80 20 in the console
( the code is not real efficient because I played around with an example of the book head first java



Java serialization is a binary format. Also, it is a format that is defined by Java. You can't just change the format to suit your needs.... okay, actually, you can somewhat by overriding the readObject() and writeObject() methods, but even then, the headers are still fixed and in binary format.

If you want to output something in an exact format, then why can't you use the object itself -- and code that gets the data and calls System.out.print() ?

Henry
 
Giovanni Montano
Ranch Hand
Posts: 607
11
Android Python Open BSD VI Editor Slackware
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Henry Wong wrote:
Java serialization is a binary format. Also, it is a format that is defined by Java. You can't just change the format to suit your needs.... okay, actually, you can somewhat by overriding the readObject() and writeObject() methods, but even then, the headers are still fixed and in binary format.


Thanks for the interest and to challenge me, it is clear, I should use the bufferedreader format, but in principle if I can "press the object" in the heap to make it binary I would like to have it back


If you want to output something in an exact format, then why can't you use the object itself -- and code that gets the data and calls System.out.print() ?

Henry


It is what I am trying to do it, i wrote the object passing the object as argument:os.writeObject(mybox2);
but how can i read it? i cannot pass mybox2 because is a local variable created inside the method scrivi() so i guess it is living in the stack and not in the heap, right?
thanks
and please Henry how can i use the scroll function, that the other sherif asked me in the past to not post large piece of code without scrolling
 
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Without scrolling" probably means "don't have lines longer than 80 characters, because they make the screen scroll." Your code is fine as far as that goes.
 
Giovanni Montano
Ranch Hand
Posts: 607
11
Android Python Open BSD VI Editor Slackware
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Knute Snortum wrote:"Without scrolling" probably means "don't have lines longer than 80 characters, because they make the screen scroll." Your code is fine as far as that goes.


cristally clear thanks
 
Knute Snortum
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I take it you want to parse what gets written to the disk because you don't know what class it is. Maybe using XMLEncoder would be easier to parse.
 
Giovanni Montano
Ranch Hand
Posts: 607
11
Android Python Open BSD VI Editor Slackware
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Knute Snortum wrote:I take it you want to parse what gets written to the disk because you don't know what class it is. Maybe using XMLEncoder would be easier to parse.


interesting thanks
 
Let me tell you a story about a man named Jed. He made this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic