Streamwriter overwriting the text in txtfile

前端 未结 2 892
没有蜡笔的小新
没有蜡笔的小新 2021-01-26 03:59

Is there some way to reopen streamwriter without it creating a new object to write to? Because at the moment, when WriteOdd is called, streamwriter is overwriting WriteEven, whi

相关标签:
2条回答
  • 2021-01-26 04:52

    Use the overload that asks you if you want to append

    public StreamWriter(
        string path,
        bool append
    )
    

    http://msdn.microsoft.com/en-us/library/36b035cb.aspx

    0 讨论(0)
  • 2021-01-26 04:52

    You can pass stream object to WriteEven() and WriteOdd() methods.

    public void WriteOdd(StreamWiter writer)
    {
      for (int i = 1; i < array.Length; i += 2)
      ...
    }
    
    0 讨论(0)
提交回复
热议问题