Sivaraj G via .NET 247 <anonymous@dotnet247.com> wrote:[color=blue]
> We created a unicode file using java application. It uses methods
> like writeUTF(), writeInt() of java.io.DataOutputStream class to
> write the content of the file. We are able to read data using
> java.io.DataInputStream.readUTF() method. It's working well in java
> environment.
>
> When we tried to read the above unicode file in .net environment. We
> received junk content not the original content.
>
> Actually we tried a sample program in c# and used
> System.Text.UTF8Encoding(true) option also. Any help highly
> appreciated.[/color]
writeUTF first writes a pair of bytes to give the number of bytes to
follow. Those aren't UTF-8 characters, but .NET would be expecting them
to be.
Effectively, writeUTF and readUTF are only designed to work with
DataInputStream/DataOutputStream. You can probably read that pair of
bytes before reading the rest, but it's not ideal. If you're just
creating a text file in Java, I suggest you use OutputStreamWriter
wrapped round a FileStream, and specify UTF-8 as the encoding. If
you're writing a file with mixed binary and text data, you need to make
sure you know *exactly* what you're writing, and then read it very
carefully from the other platform.
--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too