-
File ReadAllLinesc# 2017. 4. 15. 08:12
using System; using System.IO; class Test { public static void Main() { string path = @"c:\temp\MyTest.txt"; // This text is added only once to the file. if (!File.Exists(path)) { // Create a file to write to. string[] createText = { "Hello", "And", "Welcome" }; File.WriteAllLines(path, createText); } // This text is always added, making the file longer over time // if it is not deleted. string appendText = "This is extra text" + Environment.NewLine; File.AppendAllText(path, appendText); // Open the file to read from. string[] readText = File.ReadAllLines(path); foreach (string s in readText) { Console.WriteLine(s); } } }
'c#' 카테고리의 다른 글
LINQ-Group BY (0) 2017.05.06 C# datagridView 옵션 (0) 2017.05.02 문장에서 단어 포함여부 확인 (0) 2017.04.15 string에 헥사값 더하기 (0) 2017.04.15 stringbuilder save text file (0) 2017.04.14