/// <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(); } } }
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); }
/// <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); } }
private static async Task ExportDB() { try { File sd = Android.OS.Environment.ExternalStorageDirectory; File data = Android.OS.Environment.DataDirectory; if (sd.CanWrite()) { String currentDBPath = "/user/0/com.companyname/files/.local/share/TodoSQLite.db3"; String backupDBPath = "BackupHorarios"; File currentDB = new File(data, currentDBPath); File backupDB = new File(sd, backupDBPath); if (currentDB.Exists()) { FileChannel SourcePath = new FileInputStream(currentDB).Channel; FileChannel DestinationPath = new FileOutputStream(backupDB).Channel; await DestinationPath.TransferFromAsync(SourcePath, 0, SourcePath.Size()); SourcePath.Close(); DestinationPath.Close(); } } } catch (Exception e) { } }
public void CopyDatabase(string path) { string prefix = ""; DateTime time = DateTime.Now; prefix += $"_{time.Year}_{time.Month}_{time.Day}_{time.TimeOfDay.Hours}_{time.TimeOfDay.Minutes}_{time.TimeOfDay.Seconds}"; Java.IO.File dsFile = new Java.IO.File(path, DatabaseName + prefix + ".sqlite"); Java.IO.File dbFile = new Java.IO.File(this.ReadableDatabase.Path.Substring(0, this.ReadableDatabase.Path.Length - DatabaseName.Length - 1), DatabaseName); FileChannel inChannel = new FileInputStream(dbFile).Channel; FileChannel outChannel = new FileOutputStream(dsFile).Channel; try { inChannel?.TransferTo(0, inChannel.Size(), outChannel); } finally { inChannel?.Close(); outChannel?.Close(); } }
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; } }