在需要写字符而不是字节的情况下应该使用哪个类?
请看看java.io.Writer
和子类。
PrintWriter will be useful
http://download.oracle.com/javase/1.4.2/docs/api/java/io/PrintWriter.html
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.