Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
给定文件的路径(例如“C:\MyPicture.jpg”),如何将二进制文件转换为字节数组?
我知道我有很多 .NET 对象可供使用,例如BinaryReader、FileStream、StreamReader和其他对象,但我不确定获取二进制文件并将其转换为byte[]. 这怎么可能实现?
BinaryReader
FileStream
StreamReader
byte[]
你正在寻找File.ReadAllBytes(@"C:\MyPicture.jpg").
File.ReadAllBytes(@"C:\MyPicture.jpg")
byte[] bytes = File.ReadAllBytes("C:\\MyPicture.jpg");