From bbd27ea4a18359a4a76f9178242659a3a1c9a92d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BE=99=E8=85=BE=E7=8C=AB=E8=B7=83?= <1043137532@qq.com> Date: Mon, 4 May 2026 10:11:54 +0800 Subject: [PATCH] ref: FileStream --- Shared/Utils/FileUtils.cs | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/Shared/Utils/FileUtils.cs b/Shared/Utils/FileUtils.cs index 76fe8db..816a260 100644 --- a/Shared/Utils/FileUtils.cs +++ b/Shared/Utils/FileUtils.cs @@ -38,16 +38,32 @@ public static class FileUtils { /// /// 删除文件。 /// - public static void Delete(string filePath) => File.Delete(PathUtils.ToLongPath(filePath)); + public static void Delete(string filePath) => + File.Delete(PathUtils.ToLongPath(filePath)); /// /// 确定指定的文件是否存在。 /// - public static bool Exists(string filePath) => File.Exists(PathUtils.ToLongPath(filePath)); + public static bool Exists(string filePath) => + File.Exists(PathUtils.ToLongPath(filePath)); /// /// 创建 对象。 /// - public static FileInfo GetInfo(string path) => new(PathUtils.ToLongPath(path)); + public static FileInfo GetInfo(string path) => + new(PathUtils.ToLongPath(path)); + /// + /// 打开该文件的只读 。 + /// + public static FileStream OpenRead(string filePath) => + new(PathUtils.ToLongPath(filePath), FileMode.Open, FileAccess.Read, FileShare.ReadWrite); + + /// + /// 在指定路径创建文件,并打开 。 + /// + public static FileStream OpenCreate(string filePath) { + DirectoryUtils.Create(filePath, isFilePath: true); + return new(PathUtils.ToLongPath(filePath), FileMode.Create); + } }