Home arrow static arrow Java Programming [Archive] - Bytes and Chars plus encoding
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - Bytes and Chars plus encoding
This topic has 1 reply on 1 page.

Posts:2
Registered: 7/26/04
Bytes and Chars plus encoding  
Jul 27, 2004 12:41 AM



 
Hi,

I have a requirement to read bytes and at times characters from a given input stream. The characters in the input stream may be encoded in a particular encoding. I have a definition file, for the input stream I am supposed to read, which tells when and how much bytes/chars is to be read. Java allows to read eihter bytes or characters from a given stream. How can I read both from a given input stream?

For example, I want something like:
InputStream myInputStream;
int b = myInputStream.readByte();

// the character read below should be decoded using the appropriate
// encoding, which is known from the definition file.
int c = myInputStream.readChar();

Thanks,
Rahul.
 

Posts:2,909
Registered: 13.8.2003
Re: Bytes and Chars plus encoding  
Jul 27, 2004 12:46 AM (reply 1 of 1)



 
You can read the stream as bytes and then use Charset.decoder to decode the bytes that are actually characters.
 
This topic has 1 reply on 1 page.