|
发表于 2013-7-7 12:03:20
|
显示全部楼层
北京市北京市
[e]
private void btnIn3_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "文本文件|*.txt|所有文件|*.*";
ofd.DefaultExt = "txt";
ofd.InitialDirectory = Application.StartupPath;
ofd.Title = "导入文件";
int counts = 0;
if (ofd.ShowDialog() == DialogResult.OK)
{
FileStream fs = new FileStream(ofd.FileName, FileMode.Open);
StreamReader sr = new StreamReader(fs);
sr.BaseStream.Seek(0, SeekOrigin.Begin);
while (!sr.EndOfStream)
{
string[] ss = sr.ReadLine().Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries);
if (ss.Length==2)
{
counts++;
string[] sss = new string[3] { counts.ToString(), ss[0], ss[1] };
ListViewItem lvi = new ListViewItem(sss);
listView2.Items.Add(lvi);
}
}
}
}[/e] |
|