Java NIO(六)Channel 之间的转换(传输)
在Java NIO中,如果其中一个通道是FileChannel,则可以将数据直接从一个通道传输到另一个通道。 FileChannel类有一个transferTo()和一个transferFrom()方法,可以为你做到这一点。 transferFrom() FileChannel.transferFrom()方法将来自源通道的数据传输到FileChannel中。 这是一个简单的例子: RandomAccessFile fromFile = new RandomAccessFile("fromFile.txt", "rw"); FileChannel fromChannel = fromFile.getChannel(); RandomAccessFile toFile = new RandomAccessFile("toFile.txt", "rw"); FileChannel toChannel = toFile.getChannel(); long position = 0; long count = fromChannel.size(); toChannel.transferFro...