and i see the character are only ASCII then its not dynamic right?
any explanation for this?
other question, what is the difference between byte streams and character streams?
and i see the character are only ASCII then its not dynamic right?
any explanation for this?
other question, what is the difference between byte streams and character streams?
Bytes are not characters.
Let me repeat that: bytes are not characters.
A certain number of bytes, when decoded, can represent a character. For some encodings (like ASCII or ISO-8859-1), that certain number can be 1. But you should always be using an encoding of some sort to convert bytes to characters and vice versa, as there's not even any agreement on what char a byte might decode to.
The difference between a byte stream and a character stream is that the character stream works with characters and not bytes. If it's wrapped around a byte stream, the character stream has an encoding, and uses it to convert bytes from the underlying byte stream to characters (or of course, to convert characters written to the stream to bytes).
In C and C++, a char
holds a single byte, and the types char
is used to mean an 8-bit integer, as well as a single character of text. Java is not like that.
In Java, a char
and a byte
are different data types. A char
holds a single Unicode character which is (generally) larger than a byte. A byte
holds an 8-bit integer. When you convert a char
(or char[]
or a String
) to a byte array (type byte[]
), the string is encoded according to some character encoding (usually UTF-8), and the result is how that particular string would be stored in memory (or on disk) if it was written according to that character encoding.
Java IO supports reading byte arrays (byte[]
) directly to or from disk because this is how one generally works with binary files (i.e. non-text files, where linebreaks shouldn't be converted, and strings shouldn't be re-encoded). The bytes in that file may correspond to characters in an 8-bit encoding (like ASCII or ISO8859-*), but if you're going to use them that way, you should do an explicit conversion to a char[]
or a String
).