• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

ByteArrayOutputStream to String

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 22701
129
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually , I am working on japanese OS
 
Rob Spoor
Sheriff
Posts: 22701
129
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried with MS932 EUC-JP Shift_JIS ISO-2022-JP .But its not working
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, you probably first should find out how the stream's content is encoded.
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 3389
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
The airline is called "Virgin"? Don't you want a plane to go all the way? This tiny ad will go all the way:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic