//读取txt文件
        public void ReadTxt()
        {
            string path = @"C:\Users\Administrator\Desktop\1.txt";//文件路径
            string readline;
            string[] array;

            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)
                        {
                            Console.WriteLine("导入的数据有错误");
                            return;
                        }

                        this.DropDownList1.Items.Add(array[0]);

                    }
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.Message);
                }
            }
        }

 

相关文章:

  • 2021-12-02
  • 2021-11-12
  • 2021-12-08
  • 2022-12-23
  • 2022-12-23
  • 2021-08-16
  • 2021-11-22
  • 2021-11-11
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-07-28
  • 2022-12-23
  • 2021-09-29
  • 2022-12-23
  • 2019-08-24
相关资源
相似解决方案