Bạn có thể vượt qua một tham số thứ hai để StreamWriter
-enable
hoặc disable
phụ thêm vào tập tin:
trong C#.Net
:
using System.IO;
// This will enable appending to file.
StreamWriter stream = new StreamWriter("YourFilePath", true);
// This is default mode, not append to file and create a new file.
StreamWriter stream = new StreamWriter("YourFilePath", false);
// or
StreamWriter stream = new StreamWriter("YourFilePath");
trong C++.Net(C++/CLI)
:
using namespace System::IO;
// This will enable appending to file.
StreamWriter^ stream = gcnew StreamWriter("YourFilePath", true);
// This is default mode, not append to file and create a new file.
StreamWriter^ stream = gcnew StreamWriter("YourFilePath", false);
// or
StreamWriter^ stream = gcnew StreamWriter("YourFilePath");
Nguồn
2013-08-20 09:26:31
Và sau đó bạn có thể tạo 'StreamWriter' từ' FileStream' thay vì trực tiếp từ tên tệp: 'StreamWriter x = new StreamWriter (fcreate);' –