码迷,mamicode.com
首页 > 编程语言 > 详细

字节流和字符流 in Java

时间:2014-10-24 18:47:15      阅读:178      评论:0      收藏:0      [点我收藏+]

标签:blog   http   io   ar   使用   java   for   strong   文件   

@1:字节流:
java.io.InputStream:
public abstract class InputStream
This abstract class is the superclass of all classes representing an input stream of bytes.

java.io.OutputStream:
public abstract class OutputStream
This abstract class is the superclass of all classes representing an output stream of bytes.

InputStream是所有字节输入流的祖先,而OutputStream是所有字节输出流的祖先。

@2:字符流:
java.io.Reader:
public abstract class Reader
Abstract class for reading character streams.

java.io.Writer:
public abstract class Writer
Abstract class for writing to character streams.

Reader是所有读取字符串输入流的祖先,而Writer是所有输出字符串的祖先。

InputStream,OutputStream,Reader,writer都是抽象类。所以不能直接new。

@3:对比:

字符流使用了缓冲区,而字节流没有使用缓冲区.对于是否使用缓冲区的验证和代码示例,可以看这里.

Q:使用字节流好还是字符流好?
A:使用字节流更好.

所有的文件在硬盘或在传输时都是以字节的方式进行的,包括图片等都是按字节的方式存储的,而字符是只有在内存中才会形成,所以

在开发中,字节流使用较为广泛。

java.io中还出现了许多其他的流,主要都是为了提高性能和使用方便.

字节流和字符流 in Java

标签:blog   http   io   ar   使用   java   for   strong   文件   

原文地址:http://www.cnblogs.com/lxw0109/p/java-byte-character-stream.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!