From f478227337d61826c353e52f6d3adeb74433298f Mon Sep 17 00:00:00 2001 From: Nikita Potapov <47923521+nikita-potapov@users.noreply.github.com> Date: Sat, 26 Nov 2022 15:17:00 +0400 Subject: [PATCH] =?UTF-8?q?=D0=B7=D0=B0=D0=BF=D0=B8=D1=81=D1=8C=20=D1=87?= =?UTF-8?q?=D0=B5=D1=80=D0=B5=D0=B7=20StreamWriter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Boats/Boats/MapsCollection.cs | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/Boats/Boats/MapsCollection.cs b/Boats/Boats/MapsCollection.cs index 157cf85..8405f35 100644 --- a/Boats/Boats/MapsCollection.cs +++ b/Boats/Boats/MapsCollection.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using static System.Net.Mime.MediaTypeNames; namespace Boats { @@ -88,16 +89,6 @@ namespace Boats } } /// - /// Метод записи информации в файл - /// - /// Строка, которую следует записать - /// Поток для записи - private static void WriteToFile(string text, FileStream stream) - { - byte[] info = new UTF8Encoding(true).GetBytes(text); - stream.Write(info, 0, info.Length); - } - /// /// Сохранение информации по лодкам в хранилище в файл /// /// Путь и имя файла @@ -108,12 +99,12 @@ namespace Boats { File.Delete(filename); } - using (FileStream fs = new(filename, FileMode.Create)) + using (StreamWriter sw = File.CreateText(filename)) { - WriteToFile($"MapsCollection{Environment.NewLine}", fs); + sw.WriteLine($"MapsCollection"); foreach (var storage in _mapStorages) { - WriteToFile($"{storage.Key}{separatorDict}{storage.Value.GetData(separatorDict, separatorData)}{Environment.NewLine}", fs); + sw.WriteLine($"{storage.Key}{separatorDict}{storage.Value.GetData(separatorDict, separatorData)}"); } } return true; @@ -139,7 +130,8 @@ namespace Boats bufferTextFromFile += temp.GetString(b); } } - var strs = bufferTextFromFile.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries); + var strs = bufferTextFromFile.Split(new char[] { '\n', '\r' }, + StringSplitOptions.RemoveEmptyEntries); if (!strs[0].Contains("MapsCollection")) { //если нет такой записи, то это не те данные