Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- using System.Text.Json;
- namespace Drafty
- {
- class Program
- {
- class FileReader
- {
- public string FileName { get; set; }
- public FileReader()
- {
- string backup = Deserialize();
- Console.WriteLine($"Введите имя файла, на диске D (прошлое имя файла: {backup}):");
- Console.WriteLine("Нажмите Enter для выбора предыдущего имени файла.");
- string source = Console.ReadLine();
- if (source.Length == 0)
- {
- this.FileName = backup;
- return;
- }
- this.FileName = source;
- }
- public FileReader(string name)
- {
- this.FileName = name;
- }
- public string[] ReadFile()
- {
- string path = @$"D:\{FileName}.txt";
- if (!File.Exists(path))
- {
- Console.WriteLine("Файл не найден");
- return null;
- }
- Serialize();
- string content = File.ReadAllText(path);
- return content.Split(' ', StringSplitOptions.RemoveEmptyEntries);
- }
- private string Deserialize()
- {
- string path = @"D:\serialization.json";
- if (File.Exists(path))
- {
- return File.ReadAllText(path);
- }
- return "Не_найдено";
- }
- private void Serialize()
- {
- File.WriteAllText(@"D:\serialization.json", this.FileName);
- }
- }
- static void Main(string[] args)
- {
- FileReader writer = new FileReader();
- string[] result = writer.ReadFile();
- if (result == null)
- {
- return;
- }
- Console.WriteLine("Элементов в строке: " + result.Length);
- foreach (var item in result)
- {
- Console.Write(item + " ");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment