//验证文件夹是否存在
public string DirFilePath()
{
//文件上传后的保存路径
//获取项目文件路径可参考 : https://blog.youkuaiyun.com/oshan2012/article/details/91821229
string filePath = Path.Combine(Application.StartupPath.ToString(),"ResultContentdir");
if (!Directory.Exists(filePath))
Directory.CreateDirectory(filePath);
return filePath;
}
//方法1
private static void WriterTextContent1(string path, string content)
{
// 直接写入: File.WriteAllText(path, content);
//转换byte写入
var strByte = Encoding.UTF8.GetBytes(content);
File.WriteAllBytes(path, strByte);
}
//方法2
private static void WriterTextContent(string path, string content)
{
//if (!File.Exists(path))
// File.Create(path).Close();
using (FileStream fs = new FileStream(path,
C# 写入和读取text文件
最新推荐文章于 2025-07-06 11:27:50 发布