我用这
for($number=0; $number < 5; $number++){
StreamWriter x = new StreamWriter("C:\\test.txt");
x.WriteLine(number);
x.Close();
}
如果事情是在test.text,这code不会覆盖它。我有2个问题
if something is in test.text, this code will not overwrite it. I have 2 questions
1: how can I make it overwrite the file
2: how can I append to the same file
使用C#
尝试的FileMode枚举:
Try the FileMode enumerator:
FileStream fappend = File.Open("C:\\test.txt", FileMode.Append); // will append to end of file
FileStream fcreate = File.Open("C:\\test.txt", FileMode.Create); // will create the file or overwrite it if it already exists