java.io.FileInputStream.getChannel()方法实例

标签 java io fileinputstream

我正在处理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/

相关文章:

java - 创建文件 [] : Unsatisfied dependency expressed through constructor parameter 1 中定义的名称为 'fieldServiceImpl' 的 bean 时出错

Java IO 线程安全

c++ - 我们如何在 C++ 中一次从 STDIN 扫描 100 个字节

java - 将文件添加到 ZIP 文件

java - 如何在 Java 中使用 ObjectInputStream 读取不同的对象

java - 如何将日志写入 btrace 中的文件?

java - 如何在android中缩放矩形?

java - Eclipse IDE 插件开发 : copy files from plugin jar to active project folder

c - 从 .txt 文件中读取一行并将其拆分为 float

java - 强制删除文件夹中的所有文件