Results 1 to 2 of 2
  1. #1
    yuvalzi is offline Member
    Join Date
    Jun 2011
    Posts
    2
    Rep Power
    0

    Default Compare FileReader and FileInputStream

    hi,

    I have a file with the following char, saved as utf-8:
    "Č"

    The character is the unicode hex value "010C" (Latin Extended-A).
    As much as i understand it is saved as binary values: 00000001 00001100
    I am running on windows XP and the default character-set of the JVM is the codebase "windows-1252".

    When reading the values with java.io.FileInputStream one byte after another and print the contents to the console, i get the following values:
    196
    140

    But if i run it with java.io.FileReader i get the following values:
    196
    338

    Why is there such a difference?

    Why doesnt it print:
    1 -- equivalent to first 2 hex digits - (01)
    12 -- equivalent to last 2 hex digits - (0C)

    Thanks Yuval

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,945
    Rep Power
    19

    Default

    What code do you use for each?
    If you are simply comparing the output of a read() call on the stream compared to the reader then they will be different.
    The reader reads characters. The stream reads bytes.

Similar Threads

  1. Compare FileReader and FileInputStream
    By yuvalzi in forum New To Java
    Replies: 2
    Last Post: 06-29-2011, 03:00 PM
  2. FileReader errors
    By iochinome in forum Java Applets
    Replies: 1
    Last Post: 12-04-2010, 06:12 AM
  3. Replies: 5
    Last Post: 02-02-2010, 09:06 AM
  4. FileReader help
    By emp in forum New To Java
    Replies: 1
    Last Post: 07-28-2009, 04:41 AM
  5. add FileReader to GUI
    By VinTiger in forum New To Java
    Replies: 8
    Last Post: 05-11-2009, 12:23 AM

Posting Permissions

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