それは私のコードです
static void Write(DataTable dt, string outputFilePath)
{
int[] maxLengths = new int[dt.Columns.Count];
for (int i = 0; i < dt.Columns.Count; i++)
{
maxLengths[i] = dt.Columns[i].ColumnName.Length;
foreach (DataRow row in dt.Rows)
{
if (!row.IsNull(i))
{
int length = row[i].ToString().Length;
if (length > maxLengths[i])
{
maxLengths[i] = length;
}
}
}
}
using (StreamWriter sw = new StreamWriter(outputFilePath, false))
{
sw.Write(new byte[]{0xff,0xfe});
foreach (DataRow row in dt.Rows)
{
for (int i = 0; i < dt.Columns.Count; i++)
{
if (!row.IsNull(i))
{
sw.Write(row[i].ToString() + " ");
}
}
sw.WriteLine();
}
}
}
テキストファイルの先頭に2バイト入れたいです。
sw.Write(new byte[]{0xff,0xfe});
問題は、16 進数で開くと、これらの 2 バイトが表示されないことです。しかし、私はテキストファイル自体にこれらを見ます :\
どんな解決策でも助けてください。このように見えるはずです