C#-按行读取txt文本

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace WindowsFormsApp2
{
	public partial class Form1 : Form
	{
		public Form1()
		{
			InitializeComponent();
		}

		private void button1_Click(object sender, EventArgs e)
		{
			
			//按行读取txt文本
			string path = @"G:\Desktop\QuartzSideA-film_1.txt";
			StreamReader sr = new StreamReader(path, Encoding.Default);
			String line;
			while ((line = sr.ReadLine()) != null)
			{
				textBox1.Text += line + "\r\n";
			}			
		}
	}
}

 

你可能感兴趣的:(C#-小技能)