Results 1 to 6 of 6
  1. #1
    Lil_Aziz1's Avatar
    Lil_Aziz1 is offline Senior Member
    Join Date
    Dec 2009
    Location
    United States
    Posts
    343
    Rep Power
    5

    Default Byte vs. Character Streams

    Quote Originally Posted by Oracle
    Byte streams should only be used for the most primitive I/O
    What is considered the most "primitive I/O"? The same article also mentions that Byte Streams are kind of a low-level I/O. This might be a silly question but I had to ask, what is the difference between low-level anything and high-level anything? Is high level more efficient? Does it have more functions? Does low-level have any advantages over high level and vice-versa?

    Thanks in advance!

    Source: Byte Streams (The Java™ Tutorials > Essential Classes > Basic I/O)
    "Experience is what you get when you don't get what you want" (Dan Stanford)
    "Rise and rise again until lambs become lions" (Robin Hood)

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,874
    Rep Power
    25

    Default

    A byte is a byte. Not much lower than that.
    A character can be more than one byte and so can take some logic to match up its parts to get the whole.
    Depends what the stream has in it and what you want to get out.
    What advantage would you get reading a character stream as bytes and then having to do some more work to get the characters. Each has its own use.

  3. #3
    Lil_Aziz1's Avatar
    Lil_Aziz1 is offline Senior Member
    Join Date
    Dec 2009
    Location
    United States
    Posts
    343
    Rep Power
    5

    Default

    Okay but both Byte Stream and Character Stream do the same thing: read() returns an int (a byte) and write() converts that int to a character.

    Thus, there is no explicit difference between them.
    "Experience is what you get when you don't get what you want" (Dan Stanford)
    "Rise and rise again until lambs become lions" (Robin Hood)

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,763
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by Lil_Aziz1 View Post
    Okay but both Byte Stream and Character Stream do the same thing: read() returns an int (a byte) and write() converts that int to a character.

    Thus, there is no explicit difference between them.
    InputStreams read bytes and don't care about any character encoding. Readers also may read bytes but they decode the byte values to character values. Writing goes the other way around. This basically says what you said already but the encoding/decoding stuff is the only part which makes character level IO 'higher level' than byte level IO.

    kind regards,

    Jos

  5. #5
    Lil_Aziz1's Avatar
    Lil_Aziz1 is offline Senior Member
    Join Date
    Dec 2009
    Location
    United States
    Posts
    343
    Rep Power
    5

    Default

    So if ones locale is US and he doesn't plan to do Internalization, it really doesn't matter what type of streams he uses. Right? It might be better to do byte streams to avoid the overhead of encoding/decoding. Right?
    "Experience is what you get when you don't get what you want" (Dan Stanford)
    "Rise and rise again until lambs become lions" (Robin Hood)

  6. #6
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,874
    Rep Power
    25

    Default

    Its a trivial amount of overhead for most files.
    It would depend on what format you want the data in.
    If you need characters or if bytes will do.

Similar Threads

  1. Replies: 1
    Last Post: 04-21-2010, 03:28 AM
  2. Read from a certain character to a certain character
    By blackstormattack in forum New To Java
    Replies: 0
    Last Post: 03-16-2009, 12:36 PM
  3. reading text character by character
    By bugger in forum New To Java
    Replies: 2
    Last Post: 11-09-2007, 09:54 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •