public static bool CopyFile(File sourceFile, File destFile)
        {
            if (!destFile.Exists())
            {
                destFile.CreateNewFile();
            }

            FileChannel source      = null;
            FileChannel destination = null;

            try
            {
                source      = new FileInputStream(sourceFile).Channel;
                destination = new FileOutputStream(destFile).Channel;
                destination.TransferFrom(source, 0, source.Size());
            }
            catch (Exception e)
            {
                //FileLog.e("tmessages", e);
                return(false);
            }
            finally
            {
                if (source != null)
                {
                    source.Close();
                }

                if (destination != null)
                {
                    destination.Close();
                }
            }
            return(false);
        }
Beispiel #2
0
        /// <exception cref="System.IO.IOException"></exception>
        public static void CopyFile(FilePath sourceFile, FilePath destFile)
        {
            if (!destFile.Exists())
            {
                destFile.CreateNewFile();
            }
            FileChannel source      = null;
            FileChannel destination = null;

            try
            {
                source      = new FileInputStream(sourceFile).GetChannel();
                destination = new FileOutputStream(destFile).GetChannel();
                destination.TransferFrom(source, 0, source.Size());
            }
            finally
            {
                if (source != null)
                {
                    source.Close();
                }
                if (destination != null)
                {
                    destination.Close();
                }
            }
        }
 /// <summary>Copies a file.</summary>
 /// <remarks>Copies a file. The ordering of the parameters corresponds to the Unix cp command.</remarks>
 /// <param name="sourceFile">The file to copy.</param>
 /// <param name="destFile">The path to copy to which the file should be copied.</param>
 /// <exception cref="RuntimeIOException">If any IO problem</exception>
 public static void CopyFile(File sourceFile, File destFile)
 {
     try
     {
         if (!destFile.Exists())
         {
             destFile.CreateNewFile();
         }
     }
     catch (IOException ioe)
     {
         throw new RuntimeIOException(ioe);
     }
     try
     {
         using (FileChannel source = new FileInputStream(sourceFile).GetChannel())
         {
             using (FileChannel destination = new FileOutputStream(destFile).GetChannel())
             {
                 destination.TransferFrom(source, 0, source.Size());
             }
         }
     }
     catch (IOException e)
     {
         throw new RuntimeIOException(string.Format("FileSystem: Error copying %s to %s%n", sourceFile.GetPath(), destFile.GetPath()), e);
     }
 }
 public static void Copy(File source, File dest)
 {
     try
     {
         FileChannel inputChannel  = null;
         FileChannel outputChannel = null;
         try
         {
             inputChannel  = new FileInputStream(source).Channel;
             outputChannel = new FileOutputStream(dest).Channel;
             outputChannel.TransferFrom(inputChannel, 0, inputChannel.Size());
         }
         finally
         {
             inputChannel.Close();
             outputChannel.Close();
         }
     }
     catch (IOException ex)
     {
         throw ex;
     }
 }