Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference Between Character Stream and Byte Stream in Java and Char vs Byte in C?

Tags:

java

c

In java people say inputstream reads a file byte by byte then using buffered reader they change to characterstream.But in C char refer to byte(8 bit).Then what we call as character and byte in java.

like image 310
priwiljay Avatar asked Feb 09 '23 01:02

priwiljay


1 Answers

In Java a byte is a signed 8-bit value, and a char is an unsigned 16-bit value. The Character is both a wrapper type for char and a utility class for a number of useful method supporting char

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

I suggest you learn more about the very basics of Java. It will save you a lot of time with these sort of questions.

like image 114
Peter Lawrey Avatar answered Feb 11 '23 14:02

Peter Lawrey