4DM3M

20-21

Jan 3rd, 2022
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3.  
  4. namespace Drafty
  5. {
  6. class Program
  7. {
  8. public static string[] ReadFile()
  9. {
  10. string filename;
  11.  
  12. Console.Write("Введите имя текстового ддокумента на диске D: ");
  13. filename = Console.ReadLine();
  14.  
  15. string path = @$"D:\{filename}.txt";
  16.  
  17. if (!File.Exists(path))
  18. {
  19. Console.WriteLine("Файл не найден");
  20. return null;
  21. }
  22.  
  23. string content = File.ReadAllText(path);
  24. return content.Split(' ', StringSplitOptions.RemoveEmptyEntries);
  25. }
  26.  
  27. static void Main(string[] args)
  28. {
  29. string path = $@"D:\result.json";
  30. string[] values = ReadFile();
  31.  
  32. if (values == null)
  33. {
  34. File.WriteAllText(path, "No content found");
  35. return;
  36. }
  37.  
  38. string result = $"{values.Length}\n";
  39.  
  40. foreach (var item in values)
  41. {
  42. result += $"{item} ";
  43. }
  44.  
  45. File.WriteAllText(path, result);
  46. Console.WriteLine($"Результат записан в файл по пути {path}");
  47. }
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment