当前位置:网站首页>[C # notes] reading and writing of the contents of text files
[C # notes] reading and writing of the contents of text files
2022-07-07 02:20:00 【Start()】
Mainly used two API:
System.IO.StreamReader.ReadToEnd() // Stream reader Read the whole content of the text
System.IO.StreamWriter.Write(string value) // Stream writer Write text content to file
// Read
public string ReadTxt(string txtPath)
{
StreamReader streamReader = new StreamReader(txtPath, Encoding.Default);
string con = streamReader.ReadToEnd();
streamReader.Close();
return con;
}
// write in
/// <param name="txtPath"> File path </param>
/// <param name="writeCon"> Write content </param>
/// <param name="isCoverCon"> Whether to cover the content </param>
public void WriteTxt(string txtPath, string writeCon, bool isCoverCon = false)
{
#region If there is no text file , Just create one
if (!File.Exists(txtPath))
File.Create(txtPath).Close();
#endregion
if (!isCoverCon)
writeCon += ReadTxt(filePath);
StreamWriter streamWriter = new StreamWriter(txtPath);
streamWriter.Write(writeCon);// The content will completely cover the original text content
streamWriter.Close();
}
A newly discovered simple method , Let's record :
Use C# Encapsulated two API:
System.IO.File.ReadAllText(string path, Encoding encoding); // Read
System.IO.File.WriteAllText(string path, string contents, Encoding encoding); // write in
边栏推荐
- Several classes and functions that must be clarified when using Ceres to slam
- Collection recommandée!! Quel plug - in de gestion d'état flutter est le plus fort? Regardez le classement des manons de l'île, s'il vous plaît!
- FLIR blackfly s industrial camera: explanation and configuration of color correction and code setting method
- Decryption function calculates "task state and lifecycle management" of asynchronous task capability
- 一片葉子兩三萬?植物消費爆火背後的“陽謀”
- 2022/0524/bookstrap
- Sensor: introduction of soil moisture sensor (xh-m214) and STM32 drive code
- centos8安裝mysql報錯:The GPG keys listed for the “MySQL 8.0 Community Server“ repository are already ins
- Zabbix 5.0:通过LLD方式自动化监控阿里云RDS
- 企业中台建设新路径——低代码平台
猜你喜欢
微服务架构介绍
leetcode:5. 最长回文子串【dp + 抓着超时的尾巴】
TiFlash 源码阅读(四)TiFlash DDL 模块设计及实现分析
Jacob Steinhardt, assistant professor of UC Berkeley, predicts AI benchmark performance: AI has made faster progress in fields such as mathematics than expected, but the progress of robustness benchma
云原生混部最后一道防线:节点水位线设计
[paper reading | deep reading] rolne: improving the quality of network embedding with structural role proximity
Flir Blackfly S USB3 工业相机:计数器和定时器的使用方法
Dall-E Mini的Mega版本模型发布,已开放下载
【论文阅读|深读】DNGR:Deep Neural Networks for Learning Graph Representations
Blackfly S USB3工业相机:缓冲区处理
随机推荐
@Before, @after, @around, @afterreturning execution sequence
XML to map tool class xmlmaputils (tool class V)
长安链学习笔记-证书研究之证书模式
ROS learning (25) rviz plugin
Recommended collection!! Which is the best flutter status management plug-in? Please look at the ranking list of yard farmers on the island!
The empirical asset pricing package (EAP) can be installed through pypi
纽约大学 CITIES 研究中心招聘理学硕士和博士后
Tips for web development: skillfully use ThreadLocal to avoid layer by layer value transmission
leetcode:5. 最长回文子串【dp + 抓着超时的尾巴】
投资的再思考
3D激光SLAM:Livox激光雷达硬件时间同步
Integrated navigation: product description and interface description of zhonghaida inav2
Lidar: introduction and usage of ouster OS
Analyze "C language" [advanced] paid knowledge [i]
企业中台建设新路径——低代码平台
传感器:DS1302时钟芯片及驱动代码
#yyds干货盘点# 解决名企真题:最大差值
大咖云集|NextArch基金会云开发Meetup来啦!
Twenty or thirty thousand a leaf? "Yang Mou" behind the explosion of plant consumption
遇到慢SQL该怎么办?(下)