using System.IO;
using System.Threading.Tasks;
namespace Team.Utility
{
public static class FileHelper
{
///
/// 创建文件
///
/// 文件路径
/// 文件内容
public static void Save(string path, string str)
{
var s = path.Substring(0, path.LastIndexOf('\\'));
Directory.CreateDirectory(s); //如果文件夹不存在就创建它
using var fs = new FileStream(path, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite);
var data = System.Text.Encoding.Default.GetBytes(str);
//开始写入
fs.Write(data, 0, data.Length);
}
///
/// 创建文件
///
/// 文件路径
/// 文件内容
public static async Task SaveAsync(string path, string str)
{
var s = path.Substring(0, path.LastIndexOf('\\'));
Directory.CreateDirectory(s);//如果文件夹不存在就创建它
using var fs = new FileStream(path, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite);
var data = System.Text.Encoding.UTF8.GetBytes(str);
//开始写入
await fs.WriteAsync(data, 0, data.Length);
}
}
}