0
我正在使用visual studio 2012 C#。我有一位流媒體作家。我寫了一個文本文件的所有行,但我想把第一行放在文本文件的最後一個位置。在寫入流之後,我想將第一行切換到最後一行,但第一行不應留空,而是將先前的行向上移動,然後再次寫入流。我怎樣才能在變量中保存第一行,並開始從第二行寫入代碼的哪一部分。如何將文本文件的第一行放在最後位置
這裏是我的代碼
using (System.IO.StreamWriter file = new System.IO.StreamWriter(filepath))
{
string[] buffer = new string[count];
while (!(lines = reader.ReadLine()).Contains("Records"))
{
for (int i = 0; i < count - 1; i++)
{
string[] fields = lines.Split('|');
Result[i, 0] = "";
Result[i, 1] = fields[1];
Result[i, 2] = " ";
Result[i, 3] = xx;
Result[i, 4] = "";
Result[i, 5] = fields[4];
Result[i, 6] = "";
Result[i, 7] = fields[0];
Result[i, 8] = "";
if (fields[15].Contains("PASS"))
{
Result[i, 9] = "P";
}
else if (fields[15].Contains("FAIL"))
{
Result[i, 9] = "F";
}
Result[i, 10] = "";
Result[i, 11] = "";
Result[i, 12] = "";
Result[i, 13] = "";
Result[i, 14] = "";
}
}
else if (fields.Length == 7)
{
Result[i, 1] = "";
Result[i, 2] = "";
Result[i, 3] = fields[0]; //Test Code
Result[i, 4] = "1"; // Test Channel
Result[i, 5] =fields [4]; // Test Value
Result[i, 6] = "0"; //Test Frequency
if (fields[5].Contains("PASS"))
{
Result[i, 7] = "P";
}
else if (fields[5].Contains("FAIL"))
{
Result[i, 7] = "F";
}
Result[i, 8] = "0"; // Test Volt
Result[i, 9] = fields[1];
Result[i, 10] = "0.0";
}
}
Result[i, 11] = "0";
Result[i, 12] = "1";
Result[i, 13] = "1";
Result[i, 14] = "0";
Result[i, 15] = Profile_Index.ToString();
}
result = ("PATS_TEST" + "," + Result[i, 1] + "," + Result[i, 2] + "," + Result[i, 3] + "," + Result[i, 4] + "," + Result[i, 5] + "," + Result[i, 6] + "," + Result[i, 7] + "," + Result[i, 8] + "," + Result[i, 9] + "," + Result[i, 10] + "," + Result[i, 11] + "," + Result[i, 12] + "," + Result[i, 13] + "," + Result[i, 14] + "," + Result[i, 15]);
if (fields[0].Contains("END-OF-LINE"))
{
result = ("END-OF-LINE");
}
}
Profile_Index++;
// Console.WriteLine(result);
file.WriteLine(result);
}
它也可以是答案。感謝您的答覆。 –
@NaveenSoni不客氣。 –