aspose file tools*
The moose likes I/O and Streams and the fly likes create an OutPutStreamObject with out using files and which supports chinese characters Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "create an OutPutStreamObject with out using files and which supports chinese characters" Watch "create an OutPutStreamObject with out using files and which supports chinese characters" New topic
Author

create an OutPutStreamObject with out using files and which supports chinese characters

Apna Apana
Greenhorn

Joined: May 01, 2007
Posts: 20
Hi All,

I need an OutPutStreamObject or even PrintWriter object with out using files and which supports chinese characters(unicode)

Thanks in Advance

Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18991
    
    8

Any OutputStream will support Chinese characters, or anything in the Unicode character set for that matter... only provided you specify the charset to be used to convert those characters to bytes. You would have to use that charset when you wrote data to the OutputStream, and if that data was subsequently used by somebody else, they would also have to use that charset to convert the bytes back to chars.

Is that sufficient to answer your question? Or was your question something else, but you thought OutputStream was the answer to that question but you couldn't figure out why?
Apna Apana
Greenhorn

Joined: May 01, 2007
Posts: 20
Paul,

First of all Thanks for you reply.
I know that Streams are capable of dealing with character data. But how can I create a OutPutStream writer object or PrintWriterObject with out using files.
Another question is if I use ByteOutputStream is chinese data going to be messed up as ???.

Thanks in Advance
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19785
    
  20

To properly handle non-ASCII characters, you should wrap any InputStream / OutputStream in a Reader / Writer. The InputStreamReader and OutputStreamWriter are excellent choices to start with, as they allow you to specify the encoding to use. You then simply write the characters to the Writer, which turns it into bytes that are written to the OutputStream. The other way around, when you ask the Reader to read a character it asks the InputStream for one or more bytes to convert into the requested character.

And whatever you do, don't write non-ASCII characters to System.out. The console is very limited in what it can display. That's not a limitation in the JVM but the system's console. Using JOptionPane.showMessageDialog(null, message) usually is better.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Apna Apana
Greenhorn

Joined: May 01, 2007
Posts: 20
Thank You Rob for detailed explanation
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19785
    
  20

You're welcome
 
 
subject: create an OutPutStreamObject with out using files and which supports chinese characters