copy file using FileInputStream and FileChannel - Android File Input Output

Android examples for File Input Output:InputStream

Description

copy file using FileInputStream and FileChannel

Demo Code


//package com.java2s;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;

import java.io.IOException;
import java.nio.channels.FileChannel;

public class Main {
    public static void copy(File src, File dst) throws IOException {
        FileInputStream inStream = new FileInputStream(src);
        FileOutputStream outStream = new FileOutputStream(dst);
        FileChannel inChannel = inStream.getChannel();
        FileChannel outChannel = outStream.getChannel();
        inChannel.transferTo(0, inChannel.size(), outChannel);
        inStream.close();//  ww w  . ja  v  a  2 s.co m
        outStream.close();
    }
}

Related Tutorials