[問題] 有關文字檔寫入格式的問題
小弟想請教如何讓C#依直行順序寫入資料,也就是以一行一行的順序依序寫入資料
而非寫完一列資料 再利用換行字元\n 寫入下一行資料
例如下列程式碼 可以將資料{0,1,2,3,4,5,6,7,8,9} 的資料依照1~5烈的順序
依序列印至Test.csv檔案中
byte[] buffer;
FileStream MyFile = new FileStream("D:\Test.csv", FileMode.Create);
System.Text.ASCIIEncoding Encoder = new System.Text.ASCIIEncoding();
for(int i=0;i<5;i++)
{
for(int j=0;j<10; j++)
{
string Output = j.ToString()+", ";
buffer = Encoder.GetBytes(Output);
MyFile.Write(buffer, 0, Output.Length);
}
string NextRow = "\n";
buffer = Encoder.GetBytes(NextRow);
MyFile.Write(buffer, 0, NextRow.Length);
}
MyFile.Close();
但如果我想改變列印格式 將{0,1,2,3,4,5,6,7,8,9} 的資料直行列印 然後依照1~5
行的順序將其列印至檔案中 請問應該使用什麼樣的方法 不知道有沒有哪位前輩可以
不吝指教
謝謝
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 219.91.65.16
→
11/03 22:28, , 1F
11/03 22:28, 1F
→
11/05 06:04, , 2F
11/05 06:04, 2F
C_Sharp 近期熱門文章
PTT數位生活區 即時熱門文章