使用byte[] fileBytes = File.ReadAllBytes(filePath);
using System;
using System.IO;
class Program
{
static void Main()
{
string filePath = "D:\\1.txt";
try
{
byte[] fileBytes = File.ReadAllBytes(filePath);
Console.WriteLine("文件已成功读取为字节数组。");
// Console.WriteLine(BitConverter.ToString(fileBytes));
}
catch (Exception ex)
{
Console.WriteLine($"读取文件时发生错误: {
ex.Message}");
}
}
}
文章评论