ref: FileStream

This commit is contained in:
龙腾猫跃 committed 2026-05-04 10:11:54 +08:00
1 parent 3fe3412410
commit bbd27ea4a1
1 file changed
+19 -3
+19 -3
View File
@@ -38,16 +38,32 @@ public static class FileUtils {
/// <summary>
/// 删除文件。
/// </summary>
public static void Delete(string filePath) => File.Delete(PathUtils.ToLongPath(filePath));
public static void Delete(string filePath) =>
File.Delete(PathUtils.ToLongPath(filePath));
/// <summary>
/// 确定指定的文件是否存在。
/// </summary>
public static bool Exists(string filePath) => File.Exists(PathUtils.ToLongPath(filePath));
public static bool Exists(string filePath) =>
File.Exists(PathUtils.ToLongPath(filePath));
/// <summary>
/// 创建 <see cref="FileInfo"/> 对象。
/// </summary>
public static FileInfo GetInfo(string path) => new(PathUtils.ToLongPath(path));
public static FileInfo GetInfo(string path) =>
new(PathUtils.ToLongPath(path));
/// <summary>
/// 打开该文件的只读 <see cref="FileStream"/>。
/// </summary>
public static FileStream OpenRead(string filePath) =>
new(PathUtils.ToLongPath(filePath), FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
/// <summary>
/// 在指定路径创建文件,并打开 <see cref="FileStream"/>。
/// </summary>
public static FileStream OpenCreate(string filePath) {
DirectoryUtils.Create(filePath, isFilePath: true);
return new(PathUtils.ToLongPath(filePath), FileMode.Create);
}
}