C'est plein de sentiments maintenant, mais c'est rafraîchissant. Je veux juste me débarrasser de l'habitude d'écrire directement sur Stream.
Channels.java
ReadableByteChannel inChannel = Channels.newChannel(InputStream);
WritableByteChannel outChannel = Channels.newChannel(OutputStream);
ByteBuffer buffer = ByteBuffer.allocate(102400);
for (int readBytes = inChannel.read(buffer); readBytes != -1; readBytes = inChannel.read(buffer)) {
buffer.flip();
outChannel.write(buffer);
buffer.clear();
}
FileChannel1.java
File srcFile = new File(IN);
FileChannel in = new FileInputStream(srcFile).getChannel();
FileChannel out = new FileOutputStream(new File(OUT)).getChannel();
out.write(in.map(FileChannel.MapMode.READ_ONLY, 0, srcFile.length));
FileChannel2.java
FileChannel in = new FileInputStream(new File(IN)).getChannel();
FileChannel out = new FileOutputStream(new File(OUT)).getChannel();
in.transferTo(0, in.size(), out);