java ファイルのコピーのメモ
2007/08/09
java
FileChannel
駆け足メモ
FileChannel srcChannel = srcRaf.getChannel();
FileChannel dstChannel = dstRaf.getChannel();
srcChannel.transferTo(0, srcChannel.size(), dstChannel);
dstChannel.force(true);
FileChannel dstChannel = dstRaf.getChannel();
srcChannel.transferTo(0, srcChannel.size(), dstChannel);
dstChannel.force(true);
FileChannel srcChannel = srcRaf.getChannel();
FileChannel dstChannel = dstRaf.getChannel();
long totalLength = srcChannel.size();
dstChannel.write(srcChannel.map(FileChannel.MapMode.READ_ONLY, 0,
totalLength));
FileChannel dstChannel = dstRaf.getChannel();
long totalLength = srcChannel.size();
dstChannel.write(srcChannel.map(FileChannel.MapMode.READ_ONLY, 0,
totalLength));
FileChannel dstChannel = dstRaf.getChannel();
for (ByteBuffer buffer = ByteBuffer.allocate(1024 * 1024); srcChannel
.read(buffer) != -1; buffer.clear()) {
buffer.flip();
while (buffer.hasRemaining())
dstChannel.write(buffer);
}
for (ByteBuffer buffer = ByteBuffer.allocate(1024 * 1024); srcChannel
.read(buffer) != -1; buffer.clear()) {
buffer.flip();
while (buffer.hasRemaining())
dstChannel.write(buffer);
}
参考:
New IO Copier : FileChannel : File : Java Tutorial
: