我想创建一个方法,它可以获取任何文件并将其作为 0 和 1 的数组读取,即它的二进制代码.我想将该二进制代码保存为文本文件.你能帮助我吗?谢谢.
I want to make a method that takes any file and reads it as an array of 0s and 1s, i.e. its binary code. I want to save that binary code as a text file. Can you help me? Thanks.
又快又脏的版本:
byte[] fileBytes = File.ReadAllBytes(inputFilename);
StringBuilder sb = new StringBuilder();
foreach(byte b in fileBytes)
{
sb.Append(Convert.ToString(b, 2).PadLeft(8, '0'));
}
File.WriteAllText(outputFilename, sb.ToString());
这篇关于如何在 C# 中读取文件二进制文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!