File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ByteArrayOutputStream to String

 
Shobha Korrapati
Greenhorn
Posts: 13
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I am getting a field in ByrArrayOutpuStream . I need to convert it into String and display.Actually the data in the field has japanese characters.
I tried to convert using the method toString("UTF-8").But it is displaying junk characters
Can anyone help me out .

Thanks in advance,
Shobha
 
Rob Spoor
Sheriff
Pie
Posts: 20393
46
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe use a different encoding, that does support Japanese.

Also remember that the Windows / Unix command line also does not understand some character sets like Japanese. I even had a Linux command line that didn't recognise the "�" character. If you print to System.out you may never get it to work. Does it work in a JLabel, or a JTextArea?

Also, do you have support for the Japanese character set on you Windows / Unix / ...? If not, you won't get to see any Japanese characters either.
 
Shobha Korrapati
Greenhorn
Posts: 13
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually , I am working on japanese OS
 
Rob Spoor
Sheriff
Pie
Posts: 20393
46
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check http://java.sun.com/j2se/1.4.2/docs/guide/intl/encoding.doc.html]http://java.sun.com/j2se/1.4.2/docs/guide/intl/encoding.doc.html]http://java.sun.com/j2se/1.4.2/docs/guide/intl/encoding.doc.html

You should try one of the encodings that supports Japanese, like MS932, EUC_JP or ISO2022JP.
 
Shobha Korrapati
Greenhorn
Posts: 13
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried with MS932 EUC-JP Shift_JIS ISO-2022-JP .But its not working
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, you probably first should find out how the stream's content is encoded.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i would try UTF-16 as well. But yes, it's really best if whoever stored these bytes can tell you what encoding they use. Otherwise you can just find a list of all the encodings commonly used for Japanese, and try them all.
 
Shobha Korrapati
Greenhorn
Posts: 13
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am getting the data from a UTF-8 database.
I tried with common encoding we use like UTF-8, SHIFT_JIS , but its not working.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Shobha Korrapati:
I am getting the data from a UTF-8 database.


Who is writing to that database?
 
Raghavan Muthu
Ranch Hand
Posts: 3381
Mac MySQL Database Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I also would go with Jim. First, try to find out what encoding has been used. If not, then try with the available but related options.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the SQL datatype of the field, and how did you get the data into a ByteArrayOutputStream? I'm guessing it was a BLOB, in which case it's irrelevant that the database uses UTF-8 - you need to know what encoding was used by whoever created the BLOB.
 
H. Hall
Greenhorn
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think your problem is that java Strings are unicode format and utf8 is not.

Why don't you take a look at the DataInputStream class. The following method might be helpful:

static String readUTF(DataInput in)

Reads from the stream in a representation of a Unicode character string encoded in Java modified UTF-8 format; this string of characters is then returned as a String.

Cheers
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic