Buffers: NIO Copier, Java example Java code example - Click here to copy ->>>
Can't find what you're looking for? Try our search:
|
|
Really working examples categorized by API, package, class. You can compile and run our examples right away!
Not from source code for Java projects - only working examples! Copy, compile and run!
|
/* Title: Hardcore Java
* Title: Java I/O
* Second Edition: May 2006
* ISBN 10: 0-596-52750-0
| Code: |
import java.io.*;
import java.nio.*;
import java.nio.channels.*;
public class NIOCopier {
public static void main(String[] args) throws IOException {
FileInputStream inFile = new FileInputStream(args[0]);
FileOutputStream outFile = new FileOutputStream(args[1]);
FileChannel inChannel = inFile.getChannel();
FileChannel outChannel = outFile.getChannel();
for (ByteBuffer buffer = ByteBuffer.allocate(1024*1024);
inChannel.read(buffer) != -1;
buffer.clear()) {
buffer.flip();
while (buffer.hasRemaining()) outChannel.write(buffer);
}
inChannel.close();
outChannel.close();
}
}
|
|
|
References.
The list of classes which were used on this page you can find below. The
links to Java API contain official SUN documentation about all used classes.
[ Go Back ]
|