чтение через StreamReader

This commit is contained in:
Nikita Potapov 2022-11-26 15:24:41 +04:00
parent f478227337
commit 8062309a2c

View File

@ -120,28 +120,20 @@ namespace Boats
{
return false;
}
string bufferTextFromFile = "";
using (FileStream fs = new(filename, FileMode.Open))
using (StreamReader sr = File.OpenText(filename))
{
byte[] b = new byte[fs.Length];
UTF8Encoding temp = new(true);
while (fs.Read(b, 0, b.Length) > 0)
{
bufferTextFromFile += temp.GetString(b);
}
}
var strs = bufferTextFromFile.Split(new char[] { '\n', '\r' },
StringSplitOptions.RemoveEmptyEntries);
if (!strs[0].Contains("MapsCollection"))
string? currentLine = sr.ReadLine();
if (currentLine == null || !currentLine.Contains("MapsCollection"))
{
//если нет такой записи, то это не те данные
return false;
}
//очищаем записи
_mapStorages.Clear();
for (int i = 1; i < strs.Length; ++i)
currentLine = sr.ReadLine();
while (currentLine != null)
{
var elem = strs[i].Split(separatorDict);
var elem = currentLine.Split(separatorDict);
AbstractMap map = null;
switch (elem[1])
{
@ -161,6 +153,8 @@ namespace Boats
);
_mapStorages[elem[0]].LoadData(
elem[2].Split(separatorData, StringSplitOptions.RemoveEmptyEntries));
currentLine = sr.ReadLine();
}
}
return true;
}