fix: ReadAsBytes 不兼容正在使用中的文件
This commit is contained in:
1 parent
7402647008
commit
a10ec00951
1 file changed
+6
-2
@@ -14,8 +14,12 @@ public static class FileUtils {
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 读取文件中的所有内容。
|
/// 读取文件中的所有内容。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static byte[] ReadAsBytes(string filePath)
|
public static byte[] ReadAsBytes(string filePath) {
|
||||||
=> File.ReadAllBytes(PathUtils.WithLongPath(filePath));
|
using Stream fs = ReadAsStream(filePath); // 不能使用 File.ReadAllBytes,它不指定 FileShare.ReadWrite,会在文件被占用时抛出异常
|
||||||
|
using MemoryStream ms = new();
|
||||||
|
fs.CopyTo(ms);
|
||||||
|
return ms.ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 读取文件中的所有内容。
|
/// 读取文件中的所有内容。
|
||||||
|
|||||||
Reference in new issue
Block a user