当前位置:网站首页>[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
边栏推荐
- 云原生混部最后一道防线:节点水位线设计
- 使用Ceres进行slam必须要弄清楚的几个类和函数
- 阿里云中间件开源往事
- Infrared camera: juge infrared mag32 product introduction
- FLIR blackfly s industrial camera: configure multiple cameras for synchronous shooting
- 纽约大学 CITIES 研究中心招聘理学硕士和博士后
- 处理streamlit库上传的图片文件
- Halcon实例转OpenCvSharp(C# OpenCV)实现--瓶口缺陷检测(附源码)
- argo workflows源码解析
- 张平安:加快云上数字创新,共建产业智慧生态
猜你喜欢
15million employees are easy to manage, and the cloud native database gaussdb makes HR office more efficient
centos8安裝mysql報錯:The GPG keys listed for the “MySQL 8.0 Community Server“ repository are already ins
Blackfly S USB3工业相机:缓冲区处理
解密函数计算异步任务能力之「任务的状态及生命周期管理」
建议收藏!!Flutter状态管理插件哪家强?请看岛上码农的排行榜!
Tiflash source code reading (IV) design and implementation analysis of tiflash DDL module
一片葉子兩三萬?植物消費爆火背後的“陽謀”
FLIR blackfly s industrial camera: explanation and configuration of color correction and code setting method
ROS learning (23) action communication mechanism
Lumion 11.0软件安装包下载及安装教程
随机推荐
建議收藏!!Flutter狀態管理插件哪家强?請看島上碼農的排行榜!
How did partydao turn a tweet into a $200million product Dao in one year
ROS learning (24) plugin
张平安:加快云上数字创新,共建产业智慧生态
#yyds干货盘点# 解决名企真题:最大差值
Draco - glTF模型压缩利器
Threadlocalutils (tool class IV)
leetcode:736. Lisp 语法解析【花里胡哨 + 栈 + 状态enumaotu + slots】
Lumion 11.0 software installation package download and installation tutorial
MetaForce原力元宇宙开发搭建丨佛萨奇2.0系统开发
Unicode string converted to Chinese character decodeunicode utils (tool class II)
如何从0到1构建32Core树莓派集群
Processing image files uploaded by streamlit Library
建议收藏!!Flutter状态管理插件哪家强?请看岛上码农的排行榜!
【论文阅读|深读】DNGR:Deep Neural Networks for Learning Graph Representations
Word wrap when flex exceeds width
Infrared camera: juge infrared mag32 product introduction
机器人队伍学习方法,实现8.8倍的人力回报
ROS learning (21) robot slam function package -- installation and testing of orbslam
NPM install compilation times "cannot read properties of null (reading 'pickalgorithm')“