archangelmihail

FileUse

Jan 11th, 2014
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.38 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Security;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. class Program
  9. {
  10.     static void Main(string[] args)
  11.     {
  12.         try
  13.         {
  14.             string[] words = File.ReadAllLines("words.txt");
  15.             string[] test = File.ReadAllLines("test.txt");
  16.             string outPut = "";
  17.  
  18.             foreach (var word in words)
  19.             {
  20.                 outPut += "\"" + word + "\" :";
  21.                 int count = 0;
  22.                 foreach (var item in test)
  23.                 {
  24.                     if (item == word)
  25.                     {
  26.                         count++;
  27.                     }
  28.                 }
  29.                 outPut += count + "\r\n";
  30.             }
  31.             File.WriteAllText("result.txt", outPut);
  32.         }
  33.         catch (FileNotFoundException ex)
  34.         {
  35.             Console.WriteLine(ex.Message);
  36.         }
  37.         catch (DirectoryNotFoundException ex)
  38.         {
  39.             Console.WriteLine(ex.Message);
  40.         }
  41.         catch (IOException ex)
  42.         {
  43.             Console.WriteLine(ex.Message);
  44.         }
  45.         catch (SecurityException ex)
  46.         {
  47.             Console.WriteLine(ex.Message);
  48.         }
  49.         catch (UnauthorizedAccessException ex)
  50.         {
  51.             Console.WriteLine(ex.Message);
  52.         }
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment