using
System;
using
System.IO;
class
Program {
static
void
Main(
string
[] args)
{
string
file =
@"M:\Documents\Textfile.txt"
;
string
text =
"This is some text."
;
File.WriteAllText(file, text);
Console.WriteLine(File.ReadAllText(file));
Console.WriteLine();
string
[] textLines1 = {
"This is the first line"
,
"This is the second line"
,
"This is the third line"
};
File.WriteAllLines(file, textLines1);
Console.WriteLine(File.ReadAllText(file));
string
[] textLines2 = {
"This is the new first line"
,
"This is the new second line"
};
using
(StreamWriter writer =
new
StreamWriter(file))
{
foreach
(
string
ln
in
textLines2)
{
writer.WriteLine(ln);
}
}
Console.WriteLine(File.ReadAllText(file));
Console.ReadKey();
}
}