1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- using System.IO;
- using System.Text;
- namespace Vinno.FIS.Sonopost.Helpers
- {
- public class FileHelper
- {
- /// <summary>
- /// Save file
- /// </summary>
- public static void Save(string path, string content)
- {
- var data = new UTF8Encoding().GetBytes(content);
- using (var stream = new FileStream(path, FileMode.Create, FileAccess.Write))
- {
- stream.Write(data, 0, data.Length);
- }
- }
- public static string GetText(string path)
- {
- using (var stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))//Felix:若改为ReadWrite,SmartLogs会提示文件被占用。
- {
- byte[] buffer = new byte[stream.Length];
- stream.Read(buffer, 0, buffer.Length);
- string text = Encoding.UTF8.GetString(buffer);
- return text;
- }
- }
- public static void CopyStream(string path, Stream destStream)
- {
- using (var fs = new FileStream(path, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite))
- {
- fs.CopyTo(destStream);
- }
- }
- public static bool Exist(string path)
- {
- return File.Exists(path);
- }
- }
- }
|