diff --git a/ArmoredCar/ArmoredCar/MapsCollection.cs b/ArmoredCar/ArmoredCar/MapsCollection.cs index 0bd5205..19195c8 100644 --- a/ArmoredCar/ArmoredCar/MapsCollection.cs +++ b/ArmoredCar/ArmoredCar/MapsCollection.cs @@ -89,13 +89,14 @@ namespace ArmoredCar { File.Delete(filename); } - using (StreamWriter fs = new(filename)) + using (FileStream f = new FileStream(filename, FileMode.Create)) + using (StreamWriter sw = new StreamWriter(f, Encoding.UTF8)) { - fs.WriteLine("MapsCollection"); + sw.WriteLine("MapsCollection"); foreach (var storage in _mapStorages) { - fs.WriteLine($"{storage.Key}{separatorDict}{storage.Value.GetData(separatorDict, separatorData)}"); + sw.WriteLine($"{storage.Key}{separatorDict}{storage.Value.GetData(separatorDict, separatorData)}"); } } return true; @@ -110,15 +111,16 @@ namespace ArmoredCar if (!File.Exists(filename)) { return false; - } - using (StreamReader fs = new(filename)) + } + using (FileStream f = new(filename, FileMode.Open)) + using (StreamReader sw = new(f, Encoding.UTF8)) { - if (!fs.ReadLine().Contains("MapsCollection")) + if (!sw.ReadLine().Contains("MapsCollection")) return false; string? line; _mapStorages.Clear(); - while ((line = fs.ReadLine()) != null) + while ((line = sw.ReadLine()) != null) { var elem = line.Split(separatorDict); AbstractMap map = null;