首页 > 代码库 > java里头几个重要的IO概念
java里头几个重要的IO概念
同步与异步
阻塞还是不阻塞,轮询还是事件驱动
Netty是事件驱动的
Buffer and Stream
Java has two kinds of classes for input and output (I/O): streams and readers/writers.
Streams (InputStream, OutputStream and everything that extends these) are for reading and writing binary data from files, the network, or whatever other device.
Readers and writers are for reading and writing text (characters). They are a layer on top of streams, that converts binary data (bytes) to characters and back, using a character encoding.
Reading data from disk byte-by-byte is very inefficient. One way to speed it up is to use a buffer: instead of reading one byte at a time, you read a few thousand bytes at once, and put them in a buffer, in memory. Then you can look at the bytes in the buffer one by one.
Channel and Stream
Channel与Stream的区别在于:Channel是双向的,而Stream只能是单向的
Channel是以一个chunk一个chunk为单位读写的,但是stream说白了还是依赖一个byte一个byte的buffer
As previously mentioned, original I/O deals with data in streams, whereas NIO deals with data in blocks.
java里头几个重要的IO概念