All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.kasource.commons.util.FileUtils Maven / Gradle / Ivy

There is a newer version: 2.1
Show newest version
package org.kasource.commons.util;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.FileChannel;

/**
 * File utilities.
 *  
 * @author rikardwi
 */
public final class FileUtils {
   
    /**
     * Private constructor.
     */
    private FileUtils() { }
    

    /**
     * Copy file a file from one location to another.
     * 
     * @param in Source file
     * @param out Target file
     * 
     * @throws IOException if any error occurred.
     **/
    public static void copyFile(File in, File out) throws IOException {
     FileChannel inChannel = new
         FileInputStream(in).getChannel();
     FileChannel outChannel = new
         FileOutputStream(out).getChannel();
     try {
         inChannel.transferTo(0, inChannel.size(), outChannel);
     } 
     catch (IOException e) {
         throw e;
     }
     finally {
         if (inChannel != null)  { 
             inChannel.close();
         }
         if (outChannel != null)  {
             outChannel.close();
         }
     }
 }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy