Java FileInputStream Copy copyFile(String pathOld, String pathNew)

Here you can find the source of copyFile(String pathOld, String pathNew)

Description

copy File

License

Apache License

Declaration

public static File copyFile(String pathOld, String pathNew) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

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

import java.io.IOException;

public class Main {

    public static File copyFile(String pathOld, String pathNew) {
        File fileOld = new File(pathOld);
        File fileNew = new File(pathNew);
        if (fileOld.exists()) {
            try {
                FileInputStream fis = new FileInputStream(fileOld);
                FileOutputStream fos = new FileOutputStream(fileNew);
                int read = 0;
                while ((read = fis.read()) != -1) {
                    fos.write(read);//  w  w  w. j  a va2s . c  o  m
                    fos.flush();
                }
                fos.close();
                fis.close();
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return fileNew;
    }
}

Related

  1. copyFile(String oldFile, String newFile)
  2. copyFile(String oldPath, String newPath)
  3. copyFile(String oldPath, String newPath)
  4. copyFile(String oldPathFile, String newPathFile)
  5. copyFile(String original, String copy)
  6. copyFile(String pathOrig, String pathDst)
  7. copyFile(String quelle, String ziel)
  8. copyFile(String resourceFimeName, String targetFileName)
  9. copyFile(String s, String s1)