Java FileInputStream Copy copyFileToDir(File sourceFile, File destDir)

Here you can find the source of copyFileToDir(File sourceFile, File destDir)

Description

copy File To Dir

License

Apache License

Declaration

public static void copyFileToDir(File sourceFile, File destDir)
            throws IOException 

Method Source Code

//package com.java2s;
//Copyright 2010 ThoughtWorks, Inc. Licensed under the Apache License, Version 2.0.

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.FileOutputStream;

public class Main {
    public static void copyFileToDir(File sourceFile, File destDir)
            throws IOException {
        FileInputStream in = new FileInputStream(sourceFile);
        FileOutputStream out = new FileOutputStream(
                destDir.getAbsolutePath() + File.separator
                        + sourceFile.getName());
        byte[] buffer = new byte[1024];
        int bytesRead;
        while ((bytesRead = in.read(buffer)) > -1) {
            out.write(buffer, 0, bytesRead);
        }//  ww  w  . j av  a 2 s  .  c o  m
        out.flush();
        out.close();
    }
}

Related

  1. copyFileRecursive(File src, File dest)
  2. copyFileToAnotherDirWithRelativePaths(File srcDir, File destDir, File originalFile)
  3. copyFileToContainer(File pChild, IContainer pContainer)
  4. copyFileToDestDir(String srcFilePath, String destFileDir)
  5. copyFileToDir(File oldFile, File outputDir)
  6. copyFileToDir(String targetDir, String[] filePath)
  7. CopyFileToDirectory(String file_name, String from_directory, String to_directory)
  8. copyFileToFile(File file, File destFile, boolean overwrite)
  9. copyFileToFile(File input, String outputPath, String exportName)