Java FileInputStream Copy copyFile(String oldPath, String newPath)

Here you can find the source of copyFile(String oldPath, String newPath)

Description

copy File

License

Open Source License

Declaration

public static void copyFile(String oldPath, String newPath) throws IOException 

Method Source Code


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

public class Main {
    public static void copyFile(String oldPath, String newPath) throws IOException {
        int byteread = 0;
        File oldfile = new File(oldPath);
        InputStream inStream = null;
        FileOutputStream outStream = null;
        if (oldfile.exists()) {
            try {
                inStream = new FileInputStream(oldPath);
                outStream = new FileOutputStream(newPath);
                byte[] buffer = new byte[1024];
                while ((byteread = inStream.read(buffer)) != -1) {
                    outStream.write(buffer, 0, byteread);
                }//from  ww  w.jav  a  2  s .c  o m
            } catch (IOException ioe) {
                throw ioe;
            } finally {
                try {
                    if (inStream != null)
                        inStream.close();
                    if (outStream != null)
                        outStream.close();
                } catch (IOException e) {
                    throw e;
                }
            }
        }
    }
}

Related

  1. copyFile(String inFileName, String outFileName)
  2. copyFile(String input, String output)
  3. copyFile(String inputFile, String outputFile)
  4. copyFile(String oldFile, String newFile)
  5. copyFile(String oldPath, String newPath)
  6. copyFile(String oldPathFile, String newPathFile)
  7. copyFile(String original, String copy)
  8. copyFile(String pathOld, String pathNew)
  9. copyFile(String pathOrig, String pathDst)