CSharp - Files
Revision as of 23:38, 6 December 2012 by PeterHarding (talk | contribs) (Created page with "=Notes= Also see - http://msdn.microsoft.com/en-us/library/system.io.file.aspx <pre> using System; using System.IO; class Test { public static void Main() { ...")
Notes
Also see - http://msdn.microsoft.com/en-us/library/system.io.file.aspx
using System;
using System.IO;
class Test
{
public static void Main()
{
string path = @"c:\temp\Test.txt";
if (!File.Exists(path))
{
// Create a file to write to.
using (StreamWriter sw = File.CreateText(path))
{
sw.WriteLine("Hello World");
}
}
// Open the file to read from.
using (StreamReader sr = File.OpenText(path))
{
string s = "";
while ((s = sr.ReadLine()) != null)
{
Console.WriteLine(s);
}
}
}
}