This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Five Lines of Code and have Christian Clausen on-line!
See this thread for details.
Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

ByteArrayOutputStream to String

 
Shobha Korrapati
Greenhorn
Posts: 13
  • 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
Posts: 21971
106
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • 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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually , I am working on japanese OS
 
Rob Spoor
Sheriff
Posts: 21971
106
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • 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
  • 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
Posts: 14112
  • 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
Posts: 18671
  • 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
  • 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
Posts: 14112
  • 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: 3389
Mac MySQL Database Tomcat Server
  • 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
Posts: 18671
  • 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
  • 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
 
Can't .... do .... plaid .... So I did this tiny ad instead:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic