打开文件,读取TXT


/// <summary> /// 打开文件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button1_Click(object sender, EventArgs e) { //OpenFileDialog fileDialog = new OpenFileDialog(); //fileDialog.Multiselect = true; //fileDialog.Title = "请选择文件"; //fileDialog.Filter = "所有文件(*.*)|*.*"; //if (fileDialog.ShowDialog() == DialogResult.OK) //{ // //文件路径 // filePath = fileDialog.FileName; //} //if (filePath!=null) //{ // Read2(filePath); //} Read2(filePath); }

  

读取 文件

public void Read2(string path)
        {
            StreamReader sr;
            try
            {
                sr = new StreamReader(path, Encoding.Default);
            }
            catch (Exception)
            {
                return;
            }
          
            while ((line = sr.ReadLine()) != null)
            {
               Console.WriteLine(line.ToString());
    
            }


        }

  

猜你喜欢

转载自www.cnblogs.com/x666066/p/11465934.html