Byte Stream and Character stream

前端 未结 5 852
我在风中等你
我在风中等你 2020-11-29 18:27

Please explain what Byte streams and Character streams are. What exactly do these mean? Is a Microsoft Word document Byte oriented or Character oriented?

Thanks

5条回答
  •  野性不改
    2020-11-29 19:27

    ByteStreams:

    From oracle documentation page about byte streams:

    Programs use byte streams to perform input and output of 8-bit bytes. All byte stream classes are descended from InputStream and OutputStream.

    When to use:

    Byte streams should only be used for the most primitive I/O

    When not to use:

    You should not use Byte stream to read Character streams

    e.g. To read a text file

    Character Streams:

    From oracle documentation page about character streams:

    The Java platform stores character values using Unicode conventions. Character stream I/O automatically translates this internal format to and from the local character set.

    All character stream classes are descended from Reader and Writer.

    Character streams are often "wrappers" for byte streams. The character stream uses the byte stream to perform the physical I/O, while the character stream handles translation between characters and bytes.

    There are two general-purpose byte-to-character "bridge" streams: InputStreamReader and OutputStreamWriter.

    When to use:

    To read character streams either from Socket or File of characters

    In Summary:

    Byte stream reads and write a byte at a time. We must avoid the usage of byte stream while dealing with more sophisticated data.

    Character Stream and other available streams should be used to handle sophisticated data.

提交回复
热议问题