当前位置:网站首页>[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
边栏推荐
- 一片葉子兩三萬?植物消費爆火背後的“陽謀”
- 3D激光SLAM:Livox激光雷达硬件时间同步
- String or binary data will be truncated
- 如何从0到1构建32Core树莓派集群
- Halcon实例转OpenCvSharp(C# OpenCV)实现--瓶口缺陷检测(附源码)
- 本周 火火火火 的开源项目!
- Cisp-pte practice explanation (II)
- 将截断字符串或二进制数据
- Draco - glTF模型压缩利器
- Tiflash source code reading (IV) design and implementation analysis of tiflash DDL module
猜你喜欢

Sensor: introduction of soil moisture sensor (xh-m214) and STM32 drive code

使用Ceres进行slam必须要弄清楚的几个类和函数

STM32F4---通用定时器更新中断

Draco - glTF模型压缩利器

Livox激光雷达硬件时间同步---PPS方法

强化学习如何用于医学影像?埃默里大学最新《强化学习医学影像分析》综述,阐述最新RL医学影像分析概念、应用、挑战与未来方向

处理streamlit库上传的图片文件

ROS learning (26) dynamic parameter configuration

FLIR blackfly s industrial camera: explanation and configuration of color correction and code setting method

Stm32f4 --- PWM output
随机推荐
Livox激光雷达硬件时间同步---PPS方法
SchedulX V1.4.0及SaaS版发布,免费体验降本增效高级功能!
#夏日挑战赛#数据库学霸笔记(下)~
GEE升级,可以实现一件run tasks
1500万员工轻松管理,云原生数据库GaussDB让HR办公更高效
Stm32f4 --- general timer update interrupt
Recommended collection!! Which is the best flutter status management plug-in? Please look at the ranking list of yard farmers on the island!
【Unity】升级版·Excel数据解析,自动创建对应C#类,自动创建ScriptableObject生成类,自动序列化Asset文件
猿桌派第三季开播在即,打开出海浪潮下的开发者新视野
将截断字符串或二进制数据
New generation cloud native message queue (I)
Introduction to RC oscillator and crystal oscillator
XML to map tool class xmlmaputils (tool class V)
ROS learning (XX) robot slam function package -- installation and testing of rgbdslam
Flir Blackfly S USB3 工业相机:白平衡设置方法
Unicode string converted to Chinese character decodeunicode utils (tool class II)
ROS learning (XIX) robot slam function package cartographer
微服务架构介绍
Lidar: introduction and usage of ouster OS
Draco - glTF模型压缩利器