I/O streams in java

本文详细介绍了Java平台中字节流与字符流的概念及使用方法。包括InputStream和OutputStream类在内的字节流,用于处理8位字节输入输出;而Reader和Writer类则构成了字符流的基础,它们自动处理Unicode与本地字符集之间的转换。文章还提到了缓冲流、数据流等高级主题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Byte Streams

Programs use byte streams to perform input and output of 8-bit bytes. All byte stream classes are descended from InputStream[2] and OutputStream.[3]

 

Character Streams

The Java platform stores character values using Unicode conventions. Character stream I/O automatically translates this internal format to and from the local character set. In Western locales, the local character set is usually an 8-bit superset of ASCII.

 

All character stream classes are descended from Reader[8] and Writer.[9] As with byte streams, there are character stream classes that specialize in file I/O: FileReader[10] and FileWriter.

 

Character streams are often "wrappers" for byte streams. The character stream uses the byte stream to perform the physical I/O, while the character stream handles translation between characters and bytes. FileReader, for example, uses FileInputStream , while FileWriter uses FileOutputStream .

 

There are two general-purpose byte-to-character "bridge" streams: InputStream-Reader[13] and OutputStreamWriter.[14] Use them to create character streams when there are no prepackaged character stream classes that meet your needs. For an example that creates character streams from network byte streams, refer to the online sockets lesson.

 

There are four buffered stream classes used to wrap unbuffered streams: BufferedInputStream[19] and BufferedOutputStream[20] create buffered byte streams, while BufferedReader and BufferedWriter[21] create buffered character streams.

 

Data streams support binary I/O of primitive data type values (boolean, char, byte, short, int, long, float, and double) as well as String values. All data streams implement either the DataInput[34] or the DataOutput[35] interface. This section focuses on the most widely-used implementations of these interfaces, DataInputStream[36] and DataOutputStream.[37]

 

 

http://java.sun.com/javase/reference/index.jsp

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值