我一直面临着制作一种方法的挑战,该方法将非常大的文本文件读入程序,这些文件的范围可以从2gb到100gb.
到目前为止,这个想法一直是读取方法中的几千行文本.
目前,使用流阅读器设置程序,逐行读取文件并处理在该行上找到的必要数据区域.
using (StreamReader reader = new StreamReader("FileName"))
{
string nextline = reader.ReadLine();
string textline = null;
while (nextline != null)
{
textline = nextline;
Row rw = new Row();
var property = from matchID in xmldata
from matching in matchID.MyProperty
where matchID.ID == textline.Substring(0, 3).TrimEnd()
select matching;
string IDD = textline.Substring(0, 3).TrimEnd();
foreach (var field in property)
{
Field fl = new Field();
fl.Name = field.name;
fl.Data = textline.Substring(field.startByte - 1, field.length).TrimEnd();
fl.Order = order;
fl.Show = true; …Run Code Online (Sandbox Code Playgroud) 我一直在使用XDocument结合LINQ to XML来加载xml文件并填充我的类.
但现在我的任务是确保我的程序可以处理所有大小的XML文档,这意味着我需要使用XML Reader,此时我无法理解操纵XMLReader来填充我的类.
目前我有以下类填充:
public class DataRecord
{
private List<Fields> field = new List<Fields>();
public string ID { get; set; }
public string TotalLength { get; set; }
public List<Fields> MyProperty
{
get { return field; }
set { field = value; }
}
}
internal class Fields
{
public string name { get; set; }
public string startByte { get; set; }
public string length { get; set; }
}
}
Run Code Online (Sandbox Code Playgroud)
我一直在尝试切换语句来强制执行xmlreader以提供来自我的数据来填充类.例如:
using (XmlReader reader = XmlReader.Create(filename)) …Run Code Online (Sandbox Code Playgroud)