读一个大的.DAT文件 [英] Reading a large .DAT File
本文介绍了读一个大的.DAT文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试读取一个巨大的.DAT文件。我甚至有.DAT文件的csv,我希望从中读取特定列,例如第1列和第2列,并将列写入列表框。但是在读书的时候我得到了B A。
这是我的c#代码
I am trying to read a huge .DAT file.I even have the csv of the .DAT file from which I wish to read specific columns eg column 1 and 2 and write the columns to a listbox. But while reading I was getting B�A.
This is my c# code
private void btnLoad_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
string path = "";
ofd.FileName = "";
ofd.ShowDialog();
path = ofd.FileName;
string[] sp;
if (string.IsNullOrEmpty(ofd.FileName))
return;
string[] lines= File.ReadAllLines(path);
for (int i = 0; i < lines.Length; i++)
{
sp = lines[i].Split(',');
listBox1.Items.Add(sp[0]);
}
}
如果我在上述代码中犯了错误并请帮我纠正,请告诉我。
Please let me know if I am making a mistake in the above code and help me to rectify it.
推荐答案
我建议你阅读:关于文本文件的大量ADO [ ^ ]。这是关于使用ADO读/写文本文件的非常好的文章。请注意,该文章有点陈旧,并不符合.NET方法,虽然它值得阅读。
在这种情况下最好的方式 - 在我看来 - 是使用 ADO.NET OleDb [ ^ ]。这篇文章显示了从文本文件导入数据的两种方法:使用OleDb导入文本文件(选项卡,CSV,自定义) [ ^ ]。
试试!
请查看我过去的回答:如何使用c#将.dat文件导入数据网格 [ ^ ]
<下一组文章:
读取逗号分隔文件 [ ^ ]
读取文本文件(txt,csv,log,tab,fixed length ) [ ^ ]
[/ EDIT]
I'd suggest to read this: Much ADO About Text Files[^]. This is very good article about reading/writing text files using ADO. Note that, that article is bit old and does not corresponds to .NET methods, although it's worth of reading.
In this case the best way - in my opinion - is to use ADO.NET OleDb[^]. Here is an article which shows 2 ways to import data from text file: Using OleDb to Import Text Files (tab, CSV, custom)[^].
Try!
Please, see my past answer: how to import .dat file into datagrid using c#[^]
The next set of articles:
Reading comma delimited files[^]
Read Text File (txt, csv, log, tab, fixed length)[^]
[/EDIT]
这篇关于读一个大的.DAT文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文