当前位置:网站首页>[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
边栏推荐
- 机器人队伍学习方法,实现8.8倍的人力回报
- 一片叶子两三万?植物消费爆火背后的“阳谋”
- Analyze "C language" [advanced] paid knowledge [i]
- 传感器:土壤湿度传感器(XH-M214)介绍及stm32驱动代码
- FLIR blackfly s industrial camera: synchronous shooting of multiple cameras through external trigger
- 建议收藏!!Flutter状态管理插件哪家强?请看岛上码农的排行榜!
- BigDecimal 的正确使用方式
- Word wrap when flex exceeds width
- GEE升级,可以实现一件run tasks
- ROS learning (22) TF transformation
猜你喜欢

【服务器数据恢复】raid损坏导致戴尔某型号服务器崩溃的数据恢复案例

【论文阅读|深读】 GraphSAGE:Inductive Representation Learning on Large Graphs

ROS learning (21) robot slam function package -- installation and testing of orbslam

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!

Word wrap when flex exceeds width

解密函数计算异步任务能力之「任务的状态及生命周期管理」

Big guys gather | nextarch foundation cloud development meetup is coming!

老板被隔离了

ROS learning (26) dynamic parameter configuration

张平安:加快云上数字创新,共建产业智慧生态
随机推荐
建議收藏!!Flutter狀態管理插件哪家强?請看島上碼農的排行榜!
猫猫回收站
红外相机:巨哥红外MAG32产品介绍
传感器:土壤湿度传感器(XH-M214)介绍及stm32驱动代码
STM32F4---通用定时器更新中断
The boss is quarantined
[unity] upgraded version · Excel data analysis, automatically create corresponding C classes, automatically create scriptableobject generation classes, and automatically serialize asset files
最近小程序开发记录
GEE升级,可以实现一件run tasks
【服务器数据恢复】raid损坏导致戴尔某型号服务器崩溃的数据恢复案例
Redis configuration class redisconfig
组合导航:中海达iNAV2产品描述及接口描述
#夏日挑战赛#数据库学霸笔记(下)~
Tiflash source code reading (IV) design and implementation analysis of tiflash DDL module
Correct use of BigDecimal
Dall-E Mini的Mega版本模型发布,已开放下载
Introduction to RC oscillator and crystal oscillator
Robot team learning method to achieve 8.8 times human return
Twenty or thirty thousand a leaf? "Yang Mou" behind the explosion of plant consumption
TiFlash 源码阅读(四)TiFlash DDL 模块设计及实现分析