本文整理汇总了C#中System.IO.FileInfo.ReadAllBytes方法的典型用法代码示例。如果您正苦于以下问题:C# FileInfo.ReadAllBytes方法的具体用法?C# FileInfo.ReadAllBytes怎么用?C# FileInfo.ReadAllBytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.FileInfo
的用法示例。
在下文中一共展示了FileInfo.ReadAllBytes方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
private static void Main(string[] args)
{
// create the event loop
var loop = new EventLoop();
// start it with a callback
loop.Start(() => Console.WriteLine("Event loop has started"));
// start a timer
loop.SetTimeout(() => Console.WriteLine("Hello, I am a timeout happening after 1 second"), TimeSpan.FromSeconds(1));
loop.SetInterval(() => Console.WriteLine("Hello, I am an interval happening every 2 seconds"), TimeSpan.FromSeconds(2));
// read the app.config
var appConfigFile = new FileInfo("NLoop.TestApp.exe.config");
var promise = appConfigFile.ReadAllBytes(loop);
promise.Then(content => Console.WriteLine("Success!! read {0} bytes from app.config", content.Length), reason => Console.WriteLine("Dread!! got an error: {0}", reason));
// send a web request
var httpClient = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Get, "https://www.google.com/");
var httpPromise = httpClient.Send(loop, request);
httpPromise.Then(content => Console.WriteLine("Success!! read {0} from google.com", content.StatusCode), reason => Console.WriteLine("Dread!! got an error: {0}", reason));
//httpPromise.Cancel();
// wait
Console.WriteLine("Event loop is processing, press any key to exit");
Console.Read();
// we are done, dispose the loop so resources will be cleaned up
loop.Dispose();
}
示例2: ReadAllBytes
public void ReadAllBytes()
{
// arrange
var scheduler = new Mock<IScheduler>();
scheduler.Setup(s => s.Schedule(It.IsAny<Action>())).Callback<Action>(action => Task.Run(action));
var fileInfo = new FileInfo("NLoop.IO.Tests.dll");
// assert parameter checking
Assert.That(() => ((FileInfo) null).ReadAllBytes(scheduler.Object), Throws.InstanceOf<ArgumentNullException>());
Assert.That(() => fileInfo.ReadAllBytes(null), Throws.InstanceOf<ArgumentNullException>());
// check file not found
var notExistingFile = new FileInfo("Idonotexist.file");
var notExistingPromise = notExistingFile.ReadAllBytes(scheduler.Object);
PromiseAssert.Rejects(notExistingPromise);
// check file read
var existingPromise = fileInfo.ReadAllBytes(scheduler.Object);
PromiseAssert.Resolves(existingPromise);
}
示例3: ReadAllBytes
public void ReadAllBytes()
{
// Type
var @this = new FileInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Examples_System_IO_FileInfo_ReadAllBytes.txt"));
// Intialization
using (FileStream stream = @this.Create())
{
stream.WriteByte(0);
}
// Examples
byte[] value = @this.ReadAllBytes(); // return byte[] { 0 };
// Unit Test
Assert.AreEqual(0, value[0]);
}