using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Excel2SQL { public class TextHelper { /// /// 读取text文本内容 /// /// /// public static string ReadText(string path) { try { StreamReader sr = new StreamReader(path, Encoding.Default); String line; StringBuilder sb = new StringBuilder(); while ((line = sr.ReadLine()) != null) { sb.Append(line.ToString() + " \n"); } return sb.ToString(); } catch { throw; } } /// /// 生成文件 /// /// /// /// public static void CreateFile(string filePath, string fileName, string textContent) { if (!Directory.Exists(filePath)) { Directory.CreateDirectory(filePath); } string txtName = filePath + "\\" + fileName; using (StreamWriter outfile = new StreamWriter(txtName, false, Encoding.GetEncoding("UTF-8"))) { outfile.Write(textContent); outfile.Close(); } } } }