Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- namespace Drafty
- {
- class Program
- {
- public static string[] ReadFile()
- {
- string filename;
- Console.Write("Введите имя текстового ддокумента на диске D: ");
- filename = Console.ReadLine();
- string path = @$"D:\{filename}.txt";
- if (!File.Exists(path))
- {
- Console.WriteLine("Файл не найден");
- return null;
- }
- string content = File.ReadAllText(path);
- return content.Split(' ', StringSplitOptions.RemoveEmptyEntries);
- }
- static void Main(string[] args)
- {
- string path = $@"D:\result.json";
- string[] values = ReadFile();
- if (values == null)
- {
- File.WriteAllText(path, "No content found");
- return;
- }
- string result = $"{values.Length}\n";
- foreach (var item in values)
- {
- result += $"{item} ";
- }
- File.WriteAllText(path, result);
- Console.WriteLine($"Результат записан в файл по пути {path}");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment