CSharp examples for File IO:Text File
Process a Log File
using System;/*ww w . j a v a 2s . c o m*/ using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; class MainClass { static void Main(string[] args) { IEnumerable<string> alldata = File.ReadAllLines("all_entries.log"); foreach (string entry in alldata) { Console.WriteLine("Entry: {0}", entry); } IEnumerable<string> somedata = File.ReadLines("all_entries.log").Where(e => e.StartsWith("Error")); foreach (string entry in somedata) { Console.WriteLine("Error entry: {0}", entry); } IEnumerable<char> chardata = File.ReadLines("all_entries.log").Where(e => !e.StartsWith("Error")).Select(e => e[0]); foreach (char entry in chardata) { Console.WriteLine("Character entry: {0}", entry); } } }