我正在处理I/O
并在互联网上找到了java.io.FileInputStream.getChannel()
。我想知道 getChannel
的确切用途。为什么我们需要使用java.io.FileInputStream.getChannel()
?
示例:http://www.tutorialspoint.com/java/io/fileinputstream_getchannel.htm
最佳答案
通过创建 channel ,该流对于多个并发线程的访问是安全的。
来自 FileChannel类:
File channels are safe for use by multiple concurrent threads. The close method may be invoked at any time, as specified by the Channel interface. Only one operation that involves the channel's position or can change its file's size may be in progress at any given time; attempts to initiate a second such operation while the first is still in progress will block until the first operation completes. Other operations, in particular those that take an explicit position, may proceed concurrently; whether they in fact do so is dependent upon the underlying implementation and is therefore unspecified.
关于java.io.FileInputStream.getChannel()方法实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18894268/