[2195] in java-interest

home help back first fref pref prev next nref lref last post

Re: gets, fgets equivalents

daemon@ATHENA.MIT.EDU (Andrew Wason)
Tue Sep 26 18:44:27 1995

To: java-interest@java.Eng.Sun.COM
In-Reply-To: Message from Arthur van Hoff <Arthur.Vanhoff@eng.sun.com> 
   of "Tue, 26 Sep 95 10:14:06 -0800."   <Roam.1.2.812135646.5338.avh@acorn> 
Date: Tue, 26 Sep 95 15:52:37 -0400
From: Andrew Wason <aw@bae.bellcore.com>

Arthur van Hoff <Arthur.Vanhoff@eng.sun.com>  writes:
> 
> 
> Hi Elliotte,
> 
> > Does java have any equivalent to C's gets or fgets?  Or do I need to 
> > just read a series of bytes into an array and just convert it into a 
> > string? If the latter do the bytes in the standard input stream come 
> > in as ASCII or as Unicode?  Does anyone have sample code to do this?
> 
> Try using DataInputStream, it has a readLine method.

The implementation of readLine casts each byte read to a Unicode
char and appends it to a buffer.  I think this would only work
for reading characters in the ASCII charset (and probably
Latin1).  If I used readLine to read Unicode characters, it would
end up splitting each Unicode char into two separate bytes - so
each single Unicode char would end up spread across 4 bytes in
the buffer.

This would be even more of a problem when reading other multibyte
charsets, or single byte charsets that used a different encoding.
Are there plans to add support for other character sets and
encodings to Java (e.g. import and export to and from Unicode)?

Andrew

_______________________________________________________________________________

Andrew Wason                                       Bell Communications Research
aw@bae.bellcore.com                                Piscataway, NJ
-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com

home help back first fref pref prev next nref lref last post