• Post Reply Bookmark Topic Watch Topic
  • New Topic

read a file content of serialized object  RSS feed

 
Giovanni Montano
Ranch Hand
Posts: 428
7
Android Open BSD Slackware
  • Mark post as helpful
  • send pies
  • 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)

 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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: 428
7
Android Open BSD Slackware
  • Mark post as helpful
  • send pies
  • 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
 
Knute Snortum
Sheriff
Posts: 4270
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • 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: 428
7
Android Open BSD Slackware
  • Mark post as helpful
  • send pies
  • 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: 4270
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • 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: 428
7
Android Open BSD Slackware
  • Mark post as helpful
  • send pies
  • 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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!