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”的定义 展开
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”的定义 展开
1个回答
展开全部
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();//用完记得关闭
}
}
{
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();//用完记得关闭
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询