diff --git a/Apewer/StorageUtility.cs b/Apewer/StorageUtility.cs
index e4eb4b6..492291e 100644
--- a/Apewer/StorageUtility.cs
+++ b/Apewer/StorageUtility.cs
@@ -311,7 +311,7 @@ namespace Apewer
#region file
- /// 打开文件,并获取文件流。若文件不存在,则先创建文件;若获取失败,则返回 NULL 值。可选文件的锁定状态。
+ /// 打开文件,并获取文件流。若文件不存在,则先创建文件。
public static FileStream OpenFile(string path, bool share = true)
{
try
@@ -450,27 +450,19 @@ namespace Apewer
}
else
{
- var file = OpenFile(path, true);
- var success = false;
- try
+ using (var file = OpenFile(path, true))
{
- var dir = Path.GetDirectoryName(path);
- if (!Directory.Exists(dir)) Directory.CreateDirectory(dir);
-
- var write1 = BytesUtility.Write(file, TextUtility.Bom);
- if (write1 == TextUtility.Bom.Length)
+ try
{
- var write2 = BytesUtility.Write(file, bytes);
- if (bytes != null && bytes.LongLength > 0L)
- {
-
- }
- success = true;
+ file.SetLength(0);
+ BytesUtility.Write(file, TextUtility.Bom);
+ BytesUtility.Write(file, bytes);
+ return true;
+ }
+ catch {
+ return false;
}
}
- catch { }
- RuntimeUtility.Dispose(file);
- return success;
}
}
}