首页 > 编程语言 >C# 读取txt文本数据

C# 读取txt文本数据

时间:2023-06-06 17:33:16浏览次数:32  
标签:fs 读取 C# result strLine new txt streamReader string

public static List<string> GetTxtInfo(string FilePath,ref string errMsg)
{
List<string> result = new List<string>();
string path = FilePath;
if (File.Exists(path))
{
FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
StreamReader m_streamReader = new StreamReader(fs, System.Text.Encoding.Default);
m_streamReader.BaseStream.Seek(0, SeekOrigin.Begin);
string strLine = m_streamReader.ReadLine();
do
{
try
{
if (!string.IsNullOrEmpty(strLine))
{
result.Add(strLine);
}
}
catch (Exception err) { errMsg = err.ToString(); break; }
strLine = m_streamReader.ReadLine();
}
while (strLine != null && strLine.Trim() != "");
m_streamReader.Close();
m_streamReader.Dispose();
fs.Close();
fs.Dispose();
}
return result;
}

标签:fs,读取,C#,result,strLine,new,txt,streamReader,string
From: https://www.cnblogs.com/KevinSteven/p/17461219.html

相关文章

  • 野火指南者(STM32F103VET6)应用:实现USB虚拟串口(CDC_VPC)
    MCU:STM32F103VET6开发环境:STM32CubeMX+MDK5 实现USB的虚拟串口不需要去理解USB的底层驱动,只需要STM32CubeMX去配置生成工程即可。在野火的指南者中,是没有这一类的视频和示例的,博主使用这款开发板实现USB虚拟串口。首先需要打开STM32CubeMX工具。输入开发板MCU对应型号,找到......
  • JeeCms低代码开发平台了解及认知以及遇到的问题
    1、jeecms低代码开发平台自带标签,使用的标签延续freemarker标签或基于freemarker标签自定的标签(类似自jsp自定义标签)(1)什么是freemarker标签:FreeMarker标签是一种模板语言,用于在Java应用程序中生成动态Web页面或文本文件。它基于Java模板技术的设计思路并扩展......
  • php安装imagick扩展
    转载自:https://www.jianshu.com/p/6a1fa89281d71. 准备工作安装php如果是编译安装的PHP,pecl在php安装目录的bin子目录下,一般与php文件在同一目录。或者通过yum安装pecl:  yuminstallphp-pear php-devel2.安装imagemagickyuminstall-yImageMagickImageMagick-de......
  • ChatGPT玩法(二):AI玩转Excel表格处理
    前言在线免费体验ChatGpt:https://www.topgpt.one你是否还在为记不住Excel的繁琐函数和公式而苦恼?如果是这样,那么不妨试试ChatExcel。即使你对函数一窍不通,也能轻松处理表格。只要你能清楚地描述你的需求,它就可以帮你搞定。此外,ChatExcel的作者还制作了一张工作流程对比图,一眼就......
  • Mac 在指定目录下打开终端的方式
    参考资料:1、mac当前位置打开终端https://jingyan.baidu.com/article/ce436649281a293773afd3d8.html2、如何在MAC指定文件夹打开终端(terminal)https://www.jianshu.com/p/3e1b5fe48952......
  • AbstractQueuedSynchronizer 学习
    参考资料:1、深入浅出AQS之独占锁模式https://www.jianshu.com/p/71449a7d01af2、深入浅出AQS之共享锁模式https://www.jianshu.com/p/1161d33fc1d0独占式获取过程:1、线程调用acquire()方法获取同步状态state2、如果tryAcquire()返回为false(获取失败),将会调用addWaiter(Nod......
  • Mac 设置快速锁屏的方式
    参考资料:1、mac快速锁屏https://jingyan.baidu.com/article/219f4bf7d14984de442d389a.html2、苹果电脑快捷锁屏的几种方法https://jingyan.baidu.com/article/495ba84107f25538b30ede04.html......
  • JDK 1.6 与 1.8 中的 ConcurrentHashMap 学习
    ConcurrentHashMap使用segment(继承ReentrantLock)和volatile来保证线程安全性segment的数量为16,每个segment中桶(HashEntry[])的数量可以增加,桶中放的是由HashEntry组成的链表;count表示segment中元素的数量,modCount统计导致结构变化操作的次数(put、remove、replace......
  • 通过 Demo 理解 hashCode 与 equals 的关系
    packagecom.heatdeath.object;importlombok.extern.slf4j.Slf4j;importjava.util.HashMap;importjava.util.Map;/***Author:heatdeath*Date:2018/4/19*Desc:*/@Slf4jpublicclassEqualsDemo{publicstaticvoidmain(String[]args){......
  • Git commit –amend 修改上一次 commit message
    Gitcommit–amend修改上一次commitmessage#gitcommit-amend-m"newmessage"但是不能是已经push的提交参考资料1、git修改已提交的内容2、git之修改上次提交备注......