Java NIO(十七) AsynchronousFileChannel 异步文件通道
在Java 7中,AsynchronousFileChannel被添加到Java NIO中。 AsynchronousFileChannel可以从文件中读取数据并将数据写入文件。 本教程将解释如何使用AsynchronousFileChannel。 创建一个异步文件通道 您可以通过其静态方法open()创建一个AsynchronousFileChannel。 这里是创建一个AsynchronousFileChannel的例子: Path path = Paths.get("data/test.xml"); AsynchronousFileChannel fileChannel = AsynchronousFileChannel.open(path, StandardOpenOption.READ); open()方法的第一个参数是指向与AsynchronousFileChannel关联的文件的Path实例。 第二个参数是一个或多个打开的选项,告诉AsynchronousFileChannel在底层文件上执行什么操作。 在这个例子中,我们使用了StandardOpenOption.REA...