0
是否有某種方法可以在不創建新對象的情況下重新打開Streamwriter以寫入?因爲此刻,當WriteOdd被調用時,StreamWriter的是覆蓋WriteEven,這之前它被稱爲:/Streamwriter覆蓋txtfile中的文本
public void WriteEven()
{
StreamWriter writer = new StreamWriter(FILENAME);
for (int i = 0; i < array.Length; i+= 2)
{
Console.WriteLine(array[i]);
writer.WriteLine("EvenNumbers: " + array[i]);
}
writer.Close();
}
public void WriteOdd()
{
StreamWriter writer = new StreamWriter(FILENAME);
for (int i = 1; i < array.Length; i += 2)
{
Console.WriteLine(array[i]);
writer.WriteLine("OddNumbers: " + array[i]);
}
writer.Close();
}
感謝
@ user979649行更改爲StreamWriter的作家=新的StreamWriter(文件名,真實)使用,要求您過載; –