Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Encoding Question

 
Drew Lane
Ranch Hand
Posts: 296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm having problems reading a file with Java that was created in the .NET Framework.

Althought I can read the bytes, it seems that the encoding is not the same.

The file was created in C Sharp using a BinaryWriter, which I believe uses UTF-8 encoding.

I'm using the read(byte[],int,int) method of DataInputStream in Java.

Does anybody know how to make this work?

Thanks,

Drew
 
Paul Clapham
Sheriff
Posts: 21892
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If it's really a text file that was encoded in UTF-8, then don't mess about with the bytes. Read it as a text file that was encoded in UTF-8:
 
Drew Lane
Ranch Hand
Posts: 296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, it's not a text file. It's a binary file.
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Seems to be some confusion here. What do you have?

  • A text file, encoded in UTF-8
  • A binary file, where some parts of it are text in UTF-8
  • Something else?


  • If it's a text file, you've already been shown how to read it in UTF-8.

    If it's a binary file, in a format that's not known to Java, then you need to interpret its contents with custom code. If there are parts of the file that are text in UTF-8, then you need to isolate those parts, then you can read them using some type of Reader, again configured to use UTF-8.
     
    Drew Lane
    Ranch Hand
    Posts: 296
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thanks for the reply.

    I think I got it figured out now.

    Turns out the file was NOT a UTF-8 file as I thought.

    Drew
     
    No more fooling around. Read this tiny ad:
    the new thread boost feature brings a LOT of attention to your favorite threads
    https://coderanch.com/t/674455/Thread-Boost-feature
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!