InputStreamReader 是字节流通向字符流的桥梁。
注意一个是:字节流通向字符流,一个是:字符流通向字节流。读和写。作者: 蒋映辉 时间: 2012-6-2 20:53
阳阳啊 OutputStreamWriter 这个东西呢 叫转换流 实现把字节流转换为字符流的效果,还有对应的InputStreamReader是一样的。。。。
至于buffered 这个叫缓冲流,仔细看看里边的方法,对比一下,你会发现 字节流只能操作byte 字符流能操作char 缓冲流就可以操作字符串了,它最好用的就是readLine方法啦。
各有各的好处啦,用缓冲流比较方便,但是效率比较低,但是比如你搞个小游戏的话,就必须实用缓冲流了,我的小弹球游戏就是因为没实用双缓冲才卡的作者: 蒋映辉 时间: 2012-6-2 20:53
阳阳啊 OutputStreamWriter 这个东西呢 叫转换流 实现把字节流转换为字符流的效果,还有对应的InputStreamReader是一样的。。。。
至于buffered 这个叫缓冲流,仔细看看里边的方法,对比一下,你会发现 字节流只能操作byte 字符流能操作char 缓冲流就可以操作字符串了,它最好用的就是readLine方法啦。
各有各的好处啦,用缓冲流比较方便,但是效率比较低,但是比如你搞个小游戏的话,就必须实用缓冲流了,我的小弹球游戏就是因为没实用双缓冲才卡的作者: 张天天 时间: 2012-6-3 17:29
此文档摘自API
An OutputStreamWriter is a bridge from character streams to byte streams: Characters written to it are encoded into bytes using a specified charset. The charset that it uses may be specified by name or may be given explicitly, or the platform's default charset may be accepted.
Each invocation of a write() method causes the encoding converter to be invoked on the given character(s). The resulting bytes are accumulated in a buffer before being written to the underlying output stream. The size of this buffer may be specified, but by default it is large enough for most purposes. Note that the characters passed to the write() methods are not buffered.
下面的是程序
package io;
public static void main(String[] args) throws IOException {
DataOutputStream dos = new DataOutputStream(new BufferedOutputStream(new FileOutputStream("f:/java.txt")));
byte b = 3;
int a = 5;
float fl = 1.49f;
boolean bo = false;