Java FileInputStream Copy copyFileAsStream(String srcFilePathName, String dstFilePathName)

Here you can find the source of copyFileAsStream(String srcFilePathName, String dstFilePathName)

Description

copy File As Stream

License

Open Source License

Declaration

public static void copyFileAsStream(String srcFilePathName, String dstFilePathName) throws IOException 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.FileInputStream;
import java.io.FileOutputStream;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Reader;

import java.io.Writer;

public class Main {
    public static void copyFileAsStream(String srcFilePathName, String dstFilePathName) throws IOException {
        FileInputStream fis = new FileInputStream(srcFilePathName);
        FileOutputStream fos = new FileOutputStream(dstFilePathName);
        byte[] buf = new byte[1024];
        int i = 0;
        while ((i = fis.read(buf)) != -1) {
            fos.write(buf, 0, i);/*from   ww w .  j  a va2 s  .  c o  m*/
        }
        fis.close();
        fos.close();
    }

    public static void close(InputStream stream) {
        try {
            stream.close();
        } catch (Exception e) {
        }
    }

    public static void close(OutputStream stream) {
        try {
            stream.flush();
            stream.close();
        } catch (Exception e) {
        }
    }

    public static void close(Reader reader) {
        try {
            reader.close();
        } catch (Exception e) {
        }
    }

    public static void close(Writer writer) {
        try {
            writer.flush();
            writer.close();
        } catch (Exception e) {
        }
    }
}

Related

  1. copyFile(String srFile, String dtFile)
  2. copyFile(String srFile, String dtFile)
  3. copyFile(String srFilePath, String dtFilePath)
  4. copyFile(String target, String source)
  5. copyFileAndReName(String destPath, String srcPath, String srcFile, String destFile)
  6. copyFileBin(File sourceFile, File targetFile)
  7. copyFileBinary(String source, String destination)
  8. copyFileContents(File fromFile, File destination, boolean useTempFilenames)
  9. copyFileFolder(final File source, final File dest, final boolean override)