0

Which one is used to handle I/O on 16-bit unicode characters in java - FileInputStream/FileOutputStream or Readers/Writers? What is the difference between them?

sam100rav
  • 3,733
  • 4
  • 27
  • 43
  • 4
    The javadoc exists for this specific reason. – Sotirios Delimanolis Apr 14 '14 at 05:37
  • Follow the link : http://math.hws.edu/javanotes/c11/s1.html – Raju Sharma Apr 14 '14 at 05:39
  • 1
    Input/OutputStreams operate on bytes. Readers/Writers interpret those bytes as characters and can deal with character encodings. It took me a long time to remember this at first for some reason; an easy way to remember is that you read books and write stories - those ones are for text. – Jason C Apr 14 '14 at 05:40

1 Answers1

1

InputStreams provide raw bytes while Readers provide chars.

You can wrap an InputStream with an InputStreamReader that interpretes the bytes as unicode characters according to the encoding you define.

FileInputStream fis = new FileInputStream(..);
BufferedReader in = new BufferedReader(new InputStreamReader(fis, "utf8"));
René Link
  • 48,224
  • 13
  • 108
  • 140