当前位置: 技术问答>java相关
DataInputStream与BufferedInputStream两个流有什么区别?
来源: 互联网 发布时间:2015-05-22
本文导语: 在用这两个流上载文件时,文本文件都能正常,但上载其他文件时BufferedInputStream出错,而只能用DataInputStream?他们之间到底有什么区别? 还有当上载时,buffer的长度为request.getContentLength; read(buffer)是不是直到把整个...
在用这两个流上载文件时,文本文件都能正常,但上载其他文件时BufferedInputStream出错,而只能用DataInputStream?他们之间到底有什么区别?
还有当上载时,buffer的长度为request.getContentLength;
read(buffer)是不是直到把整个流的内容全部读入buffer中才结束?
谢谢各位大侠赐教!
还有当上载时,buffer的长度为request.getContentLength;
read(buffer)是不是直到把整个流的内容全部读入buffer中才结束?
谢谢各位大侠赐教!
|
应该不会!你用什么方法读的!?如果都是用read()的话,那应该没什么问题的呀!因为该方法是在inputstream中定义的,在两者中的实现是一样的呀!根据我的判断要不问题出在缓冲上,要不就是程序有问题.后者的可能性大一点!(你为什么要用DataInputStream啊!?这一般是用在读DataOutputstream输出的文件的!)
|
java.io
Class DataInputStream
java.lang.Object
|
+--java.io.InputStream
|
+--java.io.FilterInputStream
|
+--java.io.DataInputStream
All Implemented Interfaces:
DataInput
--------------------------------------------------------------------------------
public class DataInputStream
extends FilterInputStream
implements DataInput
A data input stream lets an application read primitive Java data types from an underlying input stream in a machine-independent way. An application uses a data output stream to write data that can later be read by a data input stream.
Data input streams and data output streams represent Unicode strings in a format that is a slight modification of UTF-8. (For more information, see X/Open Company Ltd., "File System Safe UCS Transformation Format (FSS_UTF)", X/Open Preliminary Specification, Document Number: P316. This information also appears in ISO/IEC 10646, Annex P.) Note that in the following tables, the most significant bit appears in the far left-hand column.
All characters in the range 'u0001' to 'u007F' are represented by a single byte:
0 bits 6-0
The null character 'u0000' and characters in the range 'u0080' to 'u07FF' are represented by a pair of bytes:
1 1 0 bits 10-6
1 0 bits 5-0
Characters in the range 'u0800' to 'uFFFF' are represented by three bytes:
1 1 1 0 bits 15-12
1 0 bits 11-6
1 0 bits 5-0
The two differences between this format and the "standard" UTF-8 format are the following:
The null byte 'u0000' is encoded in 2-byte format rather than 1-byte, so that the encoded strings never have embedded nulls.
Only the 1-byte, 2-byte, and 3-byte formats are used.
Class DataInputStream
java.lang.Object
|
+--java.io.InputStream
|
+--java.io.FilterInputStream
|
+--java.io.DataInputStream
All Implemented Interfaces:
DataInput
--------------------------------------------------------------------------------
public class DataInputStream
extends FilterInputStream
implements DataInput
A data input stream lets an application read primitive Java data types from an underlying input stream in a machine-independent way. An application uses a data output stream to write data that can later be read by a data input stream.
Data input streams and data output streams represent Unicode strings in a format that is a slight modification of UTF-8. (For more information, see X/Open Company Ltd., "File System Safe UCS Transformation Format (FSS_UTF)", X/Open Preliminary Specification, Document Number: P316. This information also appears in ISO/IEC 10646, Annex P.) Note that in the following tables, the most significant bit appears in the far left-hand column.
All characters in the range 'u0001' to 'u007F' are represented by a single byte:
0 bits 6-0
The null character 'u0000' and characters in the range 'u0080' to 'u07FF' are represented by a pair of bytes:
1 1 0 bits 10-6
1 0 bits 5-0
Characters in the range 'u0800' to 'uFFFF' are represented by three bytes:
1 1 1 0 bits 15-12
1 0 bits 11-6
1 0 bits 5-0
The two differences between this format and the "standard" UTF-8 format are the following:
The null byte 'u0000' is encoded in 2-byte format rather than 1-byte, so that the encoded strings never have embedded nulls.
Only the 1-byte, 2-byte, and 3-byte formats are used.
|
DataInputSteam:可以读输入流基本类型的操作,比如readInt(),readDouble(),readLong()...
BufferedInputStream是FileterInputStream子类,避免每次都物理得读取,告诉从缓冲区读,和FileInputSteam等InputStream子类联合使用(非FileterInputStream).
BufferedInputStream是FileterInputStream子类,避免每次都物理得读取,告诉从缓冲区读,和FileInputSteam等InputStream子类联合使用(非FileterInputStream).
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。