当前位置:网站首页>C#【文件操作篇】按行读取txt文本
C#【文件操作篇】按行读取txt文本
2022-04-23 05:47:00 【明如正午】
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";
}
//方法二:
string[] strArray=File.ReadAllLines(path);
for(int i=0;i<strArray.Length;i++)
{
textBox1.Text += strArray[i]+ "\r\n";
}
}
}
}
版权声明
本文为[明如正午]所创,转载请带上原文链接,感谢
https://star-302.blog.csdn.net/article/details/102655281
边栏推荐
- 【UDS统一诊断服务】四、诊断典型服务(2)— 数据传输功能单元
- SQL -- data definition
- [leetcode 350] intersection of two arrays II
- Introduction to virtualization features
- xlsxwriter.exceptions.FileCreateError: [Errno 13] Permission denied问题
- Understanding and installing MySQL
- Linux 用rpm的方式安装mysql(超简单)
- 【UDS统一诊断服务】一、诊断概述(3)— ISO 15765体系结构
- Busybox initrd and initialization process
- 基于pygame库编写的五子棋游戏
猜你喜欢
随机推荐
类和对象的初始化(构造函数与析构函数)
[leetcode 290] word rules
【OpenCV】使用 FileStorage 读写 Eigen 向量
C语言输入和输出(printf和scanf函数、putchar和getchar函数)
非参数化相机畸变模型简介
gcc ,g++,gdb的安装
【UDS统一诊断服务】四、诊断典型服务(2)— 数据传输功能单元
从源代码到可执行文件的过程
Explanation of login page
Solution to the trial of ycu Blue Bridge Cup programming competition in 2021
Cf515b drazil and his happy friends
[leetcode 59] spiral matrix II
【UDS统一诊断服务】四、诊断典型服务(3)— 读故障信息功能单元(存储数据传输功能单元)
利用文件保存数据(c语言)
日志
类的继承与派生
jenkspy包安装
大学概率论与数理统计知识点详细整理
H. Are You Safe? Convex hull naked problem
如何安装jsonpath包