public static void copyFile(String srcPath,String destPath) throws Exception {
  File srcFile=new File(srcPath);
  File destFile=new File(destPath);
  if (!srcFile.exists()) {
    throw new Exception("source file does not exist");
  }
  String srcFileLocation=srcFile.getAbsolutePath();
  String destFileLocation=destFile.getAbsolutePath();
  if (srcFileLocation.equals(destFileLocation)) {
    throw new Exception("source and destination are the same file");
  }
  InputStream input=new FileInputStream(srcFile);
  OutputStream output=new FileOutputStream(destFile);
  byte[] buf=new byte[1024];
  int length;
  while ((length=input.read(buf)) > 0) {
    output.write(buf,0,length);
  }
  input.close();
  output.close();
}

public static void copyFile ( String srcPath , String destPath ) throws Exception { File srcFile = new File ( srcPath ) ; File destFile = new File ( destPath ) ; if ( ! srcFile . exists ( ) ) { throw new Exception ( "source file does not exist" ) ; } String srcFileLocation = srcFile . getAbsolutePath ( ) ; String destFileLocation = destFile . getAbsolutePath ( ) ; if ( srcFileLocation . equals ( destFileLocation ) ) { throw new Exception ( "source and destination are the same file" ) ; } InputStream input = new FileInputStream ( srcFile ) ; OutputStream output = new FileOutputStream ( destFile ) ; byte [ ] buf = new byte [ 1024 ] ; int length ; while ( ( length = input . read ( buf ) ) > 0 ) { output . write ( buf , 0 , length ) ; } input . close ( ) ; output . close ( ) ; }
copy a file on the local filesystem
