Open the file, read TXT


/// <Summary> /// open file /// </ Summary> /// <param name = "SENDER"> </ param> /// <param name = "E"> </ param> Private void the button1_Click (SENDER Object, EventArgs E) { // new new = the OpenFileDialog fileDialog the OpenFileDialog (); //fileDialog.Multiselect = to true; //fileDialog.Title = "select file"; //fileDialog.Filter = "all files (* . *) | * * ";. // IF (fileDialog.ShowDialog () == DialogResult.OK) // { // // file path // filePath = fileDialog.FileName; //} //if (filePath!=null) //{ // Read2(filePath); //} Read2(filePath); }

  

 

Read the file

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());
    
            }


        }

  

Guess you like

Origin www.cnblogs.com/x666066/p/11465934.html