【摘要】 目录
第一步新建txt文件,写入内容
第二步读取数据
最终效果图第一步新建txt文件,写入内容
我是放在D盘下的,数据以逗号隔开的,是英文逗号第二步读取数据
在需要读取数据的页面,添加代码,就可以了
private void Phone_Load(object sender, EventArgs e) { string ReadLine; stri…
目录
第一步新建txt文件,写入内容
我是放在D盘下的,数据以逗号隔开的,是英文逗号
第二步读取数据
在需要读取数据的页面,添加代码,就可以了
private void Phone_Load(object sender, EventArgs e)
{
string ReadLine;
string[] array;
string Path = @"D:\FrontierApp.TXT";
StreamReader reader = new StreamReader(Path,System.Text.Encoding.GetEncoding("GB2312"));
while (reader.Peek() >= 0)
{
try
{
ReadLine = reader.ReadLine();
if (ReadLine != "")
{
ReadLine = ReadLine.Replace("\"", "");
array = ReadLine.Split(',');
if (array.Length == 0)
{
MessageBox.Show("您选择的导入数据类型有误,请重试!");
return;
}
for (int i = 0; i < array.Length; i++)
{
comboBox2.Items.Add(array[i]);
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
}
© 版权声明文章版权归作者所有,未经允许请勿转载。THE END
喜欢就支持一下吧
相关推荐