using System; using System.Configuration; using System.Collections.Generic; using System.Text; using System.Web; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.Security; using System.IO; using System.IO.Compression; using System.Xml; using System.Diagnostics; using System.Windows.Forms; using System.Threading; namespace HH.WMS.Utils { public partial class ZFiles { #region 以只读方式读取文本文件 /// /// 以只读方式读取文本文件 /// /// 文件路径及文件名 /// public static string ReadTxtFile(string FilePath) { string content = "";//返回的字符串 using (FileStream fs = new FileStream(FilePath, FileMode.Open, FileAccess.Read, FileShare.Read)) { using (StreamReader reader = new StreamReader(fs, Encoding.UTF8)) { string text = string.Empty; while (!reader.EndOfStream) { text += reader.ReadLine() + "\r\n"; content = text; } } } return content; } public static string ReadFile(string FilePath) { string text = string.Empty; System.Text.Encoding code = System.Text.Encoding.GetEncoding("gb2312"); using (var sr = new StreamReader(FilePath, code)) { try { text = sr.ReadToEnd(); // 读取文件 sr.Close(); } catch { } } return text; } #endregion } }