What is the difference between character stream and byte stream in Java and Char vs Byte in C?

In java, people say that the input stream reads a byte file byte, and then uses a buffered reader, which they change to characterstream. But in C, char refers to bytes (8 bits). Then we call the character and byte in java.

+4
source share
3 answers

In Java, a byteis a signed 8-bit value, and chara unsigned 16-bit value. Characteris both a shell type for charand a utility class for a number of useful methods that supportchar

The key difference between the InputStream is that it reads binary data, one byte at a time. A Readeris for reading text, and it decodes bytes in char, using the character encoding you set, or the default encoding, for example. UTF-8can turn 1, 2 or 3 bytes into one char.

I suggest you learn more about the very basics of Java. This will save you a lot of time on such questions.

+7
source

For the C / C ++ part, in these languages, char is guaranteed to be at least 8 bits, so char is no less than width than byte. I have been coding C since 1990 and C ++ since 1992, and I have never seen a real platform / compiler combination where char and byte are not equivalent.

, , (, "int" - ), "char" "unsigned char".

0

- . Streams , . , , , , .. Java - , char. , . , Java : .

. Java- 8- . , . , Unicode, , , . - , (UNICODE). InputStream OutputStream.

0

Source: https://habr.com/ru/post/1607406/


All Articles