• Post Reply Bookmark Topic Watch Topic
  • New Topic

What is this ��

 
Nikos Stavros
Ranch Hand
Posts: 243
Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when I write data I get this weird stuff at the start

�� and then 2 squares for the next two characters



any ideas
[ July 05, 2006: Message edited by: Nikos Katsikanis ]
 
Martin Simons
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It has to do with character encoding. It is most likely written in UTF-8 and the thing you are reading it with can't do UTF-8. Or, the source is not UTF-8, but Java is treating it as though it is, and so writes it as UTF-8 even though it is not.


(Sorry, I am a Fool sometimes. I saw the title and the FileOutputStream and then completely overlooked the ObjectOutputStream, so I latched onto encoding like a pit bull. That's what I get for not looking at a problem carefully.)
[ July 05, 2006: Message edited by: Martin Simons ]
 
Henry Wong
author
Sheriff
Posts: 22519
109
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is how object serialization works...

It is saving information that it is a string that you are serializing, along with everything needed to be able to deserialize the string later.

BTW, it may not be a good idea to wrap a print stream around a object output stream. You may want to be able to deserialize from the file later, and find it difficult to reverse what the print stream wrote -- unless you did it yourself.

Henry
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 15713
73
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do you create an ObjectOutputStream in your source code? You're not using it, so don't create it. Change your code to this:

If you want to change the character encoding that is used to write the text to the file, you can use class OutputStreamWriter, it allows you to set the encoding. See the API documentation.
[ July 05, 2006: Message edited by: Jesper Young ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!