public void TestAppendText() { var filename = new StringBuilder(longPathDirectory).Append(@"\").Append("file16.ext").ToString(); using (var writer = File.CreateText(filename)) { writer.Write("start"); } Assert.IsTrue(File.Exists(filename)); try { using (var writer = new FileInfo(filename).AppendText()) { writer.WriteLine("end"); } using (var reader = File.OpenText(filename)) { var text = reader.ReadLine(); Assert.AreEqual("startend", text); } } finally { File.Delete(filename); } }
public void TestCreateText() { var filename = new StringBuilder(longPathDirectory).Append(@"\").Append("file3.ext").ToString(); const string fileText = "test"; using (var writer = File.CreateText(filename)) { writer.WriteLine(fileText); } try { Assert.IsTrue(File.Exists(filename)); using (var reader = File.OpenText(filename)) { var text = reader.ReadLine(); Assert.AreEqual(fileText, text); } } finally { File.Delete(filename); } }
public static StreamReader OpenText(string path) { return(File.OpenText(path)); }