我有一些 C++ 代码通过 STL 字符串和文本 i/o 将字节值保存到文件中,并且对如何在 C# 中执行此操作感到困惑。
首先,我将字节数组转换为字符串并将每个数组作为一行存储在文本文件中:
StreamWriter F
loop
{
byte[] B; // array of byte values from 0-255 (but never LF,CR or EOF)
string S = B; // I'd like to do this assignment in C# (encoding? ugh.) (*)
F.WriteLine(S); // and store the byte values into a text file
}
稍后...我想颠倒这些步骤并取回原始字节值:
StreamReader F;
loop
{
string S = F.ReadLine(); // read that line back from the file
byte[] B = S; // I'd like to convert back to byte array (*)
}
你是怎么做这些作业的(*)?