Android File 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) 

Method Source Code

//License from project: Open Source License 

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import javax.servlet.ServletContext;

public class Main{
    public static void copyFile(String oldPath, String newPath) {
        try {/*from  w ww . j av a 2 s  .c  o m*/
            int byteread = 0;
            File oldfile = new File(oldPath);
            if (oldfile.exists()) {
                InputStream inStream = new FileInputStream(oldPath); 
                FileOutputStream fs = new FileOutputStream(newPath);
                byte[] buffer = new byte[10000];
                while ((byteread = inStream.read(buffer)) != -1) {
                    fs.write(buffer, 0, byteread);
                }
                inStream.close();
                fs.close();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

Related

  1. copyFile(File src, File dest)
  2. copyFile(File src, File dst)
  3. copyFile(Path source, Path target)
  4. copyFile(String from, String target)
  5. copyFile(String from, String to)
  6. copyFile(String origPath, String destPath)
  7. copyFile(String sourceFileName, String destinationFileName)
  8. copyFile(String sourcePath, String destPath)
  9. copyFile(String sourcePathName, String destPathName)