Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which Class used for writing characters rather than bytes?

Tags:

java

Which class should be used in situations that require writing characters rather than bytes?

like image 973
aTJ Avatar asked Jan 14 '11 12:01

aTJ


3 Answers

Please take a look at java.io.Writer and subclasses.

like image 173
Mot Avatar answered Sep 28 '22 07:09

Mot


PrintWriter will be useful

http://download.oracle.com/javase/1.4.2/docs/api/java/io/PrintWriter.html

like image 43
Abi Avatar answered Sep 28 '22 07:09

Abi


An important thing to know about I/O in Java is that streams (InputStream and OutputStream etc.) are used for reading and writing binary data (you read or write bytes exactly as they are in the file), and readers and writers (Reader and Writer etc.) are for reading and writing characters.

Readers and writers are a layer on top of streams. A Reader interprets the bytes from an InputStream using a character encoding (such as UTF-8, ISO-8859-1, US-ASCII) to convert them into characters, and a Writer uses a character encoding to turn characters into bytes.

like image 21
Jesper Avatar answered Sep 28 '22 09:09

Jesper