本文整理匯總了C#中System.IO.File.OpenRead方法的典型用法代碼示例。如果您正苦於以下問題:C# File.OpenRead方法的具體用法?C# File.OpenRead怎麽用?C# File.OpenRead使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.IO.File
的用法示例。
在下文中一共展示了File.OpenRead方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: TestSameCore
private void TestSameCore(File memTempFile, File localTempFile, FileMode mode, FileAccess access, FileShare share)
{
Stream memStream = null, localStream = null;
Exception memException = null, localException = null;
try
{
memStream = memTempFile.Open(mode, access, share);
}
catch (Exception e)
{
memException = e;
}
try
{
localStream = localTempFile.Open(mode, access, share);
}
catch (Exception e)
{
localException = e;
}
if (memException != null || localException != null)
{
if (memStream != null) memStream.Dispose();
if (localStream != null) localStream.Dispose();
var anyException = (memException ?? localException).GetType();
Assert.That(memException, Is.InstanceOf(anyException), string.Format("In-Memory ex was {0}, but file was: {1}",
memException != null ? memException.ToString() : "NULL",
localException != null ? localException.ToString() : "NULL"));
Assert.That(localException, Is.InstanceOf(anyException), string.Format("Local file ex was {0}, but in mem was: {1}.",
localException != null ? localException.ToString() : "NULL",
memException != null ? memException.ToString() : "NULL"));
if (!(memException.GetType() == anyException && localException.GetType() == anyException))
Console.WriteLine("Memory exception: " + (memException != null ? memException.GetType().Name : null) +
" Local exception: " + (localException != null ? localException.GetType().Name : null));
return;
}
if (memStream.CanWrite)
memStream.WriteByte(99);
if (localStream.CanWrite)
localStream.WriteByte(99);
memStream.Dispose();
localStream.Dispose();
using (memStream = memTempFile.OpenRead())
using (localStream = localTempFile.OpenRead())
{
memStream.ReadToEnd().ShouldBe(localStream.ReadToEnd());
localStream.Close();
memStream.Close();
}
}