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";
			}			
		}
	}
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章