string readme = "readme.txt"; //文件名称
string txtpath = path + "/" + readme;//文件存放路径
DirectoryInfo directoryInfo = new DirectoryInfo(path);
if (!directoryInfo.Exists) //判断 文件夹是否存在
{
directoryInfo.Create();
}
if (!File.Exists(txtpath)) {
File.Create(txtpath).Close();//判断文件是否存在,创建txt文件后需要close,否则会出现文件占用情况
}
StreamWriter sw = new StreamWriter(txtpath, true, System.Text.Encoding.Default);//第一个参数代表路径,第二个参数表示文件是否覆盖还是在原有文件基础上添加,第三个参数代表编码格式
sw.WriteLine("存放原始照片");//写入txt文件
sw.WriteLine("存放过程照片");
sw.WriteLine("存放结果照片");
sw.Flush();
sw.Close();
C# 写入数据到txt文件
最新推荐文章于 2024-04-21 22:09:55 发布