C#System.IO.File”并不包含“ReadLines”的定义

usingMicrosoft.Win32;usingSystem;usingSystem.Collections.Generic;usingSystem.IO;using... using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace 读取文件内容添加到数据库
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}

private void Button_Click(object sender, RoutedEventArgs e)
{
OpenFileDialog OFD = new OpenFileDialog();
OFD.Filter = "文本文件|*.txt";
if(OFD.ShowDialog()==false)
{
return;
}
string[] lines =
File.ReadLines(OFD.FileName, Encoding.Default).ToArray();
for (int i = 1; i < lines.Count(); i++)
{
string line = lines[i];
string[] strs=line.Split('\t');
string startTelNum = strs[0];
string city = strs[1];
city = city.Trim('"');//去掉两边的双引号:"北京市"
string telType = strs[2];
telType = telType.Trim('"');

}
}
}
}
错误 1 “System.IO.File”并不包含“ReadLines”的定义
展开
 我来答
wangyan954
2014-03-27
知道答主
回答量:10
采纳率:0%
帮助的人:10.9万
展开全部
private void Button_Click(object sender, EventArgs e)
{
OpenFileDialog OFD = new OpenFileDialog();
OFD.Filter = "文本文件|*.txt";
if (DialogResult.OK.Equals(OFD.ShowDialog()))
{
FileStream fileStream = File.OpenRead(OFD.FileName);
StreamReader streamReader = new StreamReader(fileStream);
string line = string.Empty;
while (!string.IsNullOrEmpty((line = streamReader.ReadLine())))
{
string[] strs = line.Split('\t');
string startTelNum = strs[0];
string city = strs[1];
city = city.Trim('"');//去掉两边的双引号:"北京市"
string telType = strs[2];
telType = telType.Trim('"');
}
streamReader.Close();//用完记得关闭
fileStream.Close();//用完记得关闭
}
}
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式