Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Example for FileInputStream and FileOutputStream
- import java.io.*;
- import java.nio.channels.*;
- public class CopyFileChannel {
- public static void main(String[] args) {
- if (args.length < 2) {
- System.out.println("Please provide input and output files");
- System.exit(0);
- }
- String inputFile = args[0];
- String outputFile = args[1];
- try (
- FileChannel sourceChannel = new FileInputStream(inputFile).getChannel();
- FileChannel destChannel = new FileOutputStream(outputFile).getChannel();
- ) {
- sourceChannel.transferTo(0, sourceChannel.size(), destChannel);
- } catch (IOException ex) {
- ex.printStackTrace();
- }
- }
- }
Add Comment
Please, Sign In to add comment