Loading...

java ファイルのコピーのメモ

FileChannel
駆け足メモ

FileChannel srcChannel = srcRaf.getChannel();
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();
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
リアクション: 
java 3355179450972251188

コメントを投稿

ホーム item

このブログを検索

Random Posts

Popular Posts

Labels

ADS