7using System.Threading.Tasks;
14 internal static class FileHelper
46 public static void WriteTextToFile(
string path,
string text)
48 string? directory = Path.GetDirectoryName(path);
49 if (directory !=
null && !Directory.Exists(directory))
51 Directory.CreateDirectory(directory);
54 File.WriteAllText(path, text);
90 public static async Task WriteTextToFileAsync(
string path,
string text, CancellationToken cancellationToken =
default)
92 if (cancellationToken.IsCancellationRequested)
97 string? directory = Path.GetDirectoryName(path);
98 if (directory !=
null && !Directory.Exists(directory))
100 Directory.CreateDirectory(directory);
103#if NETCOREAPP3_1_OR_GREATER
104 await File.WriteAllTextAsync(path, text, cancellationToken);
107 if (File.Exists(path))
112 using StreamWriter fileStream = File.CreateText(path);
113 await fileStream.WriteAsync(text);