本文整理汇总了C#中FileEntry.Open方法的典型用法代码示例。如果您正苦于以下问题:C# FileEntry.Open方法的具体用法?C# FileEntry.Open怎么用?C# FileEntry.Open使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileEntry
的用法示例。
在下文中一共展示了FileEntry.Open方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateFile
private NativeFileEntry CreateFile(FileEntry entry)
{
var fullPath = Path.Combine(this.BaseDirectory, entry.RelativePath);
if (this.FileSystem.File.Exists(fullPath))
this.FileSystem.File.Delete(fullPath);
using (var destStream = entry.Open())
using (var sourceStream = this.FileSystem.File.Create(fullPath).StreamInstance)
{
byte[] buffer = new byte[1024];
int offset = 0;
while (true)
{
int bytesRead = destStream.Read(buffer, 0, buffer.Length);
if (bytesRead <= 0)
break;
sourceStream.Write(buffer, 0, bytesRead);
offset += bytesRead;
if (bytesRead < buffer.Length)
break;
}
sourceStream.Flush();
}
var info = this.FileSystem.GetFileInfo(fullPath);
return new NativeFileEntry(info)
{
BaseDirectory = this.BaseDirectory,
Created = info.CreationTimeUtc.DateTimeInstance,
Modified = info.LastWriteTimeUtc.DateTimeInstance,
RelativePath = entry.RelativePath
};
}