schangxiang@126.com
2025-08-05 04d10bce51a6272d02a4a0f1b05a4f64bf73f273
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace Excel2SQL
{
    public class TextHelper
    {
        /// <summary>
        /// 读取text文本内容
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        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;
            }
        }
 
        /// <summary>
        /// 生成文件
        /// </summary>
        /// <param name="filePath"></param>
        /// <param name="fileName"></param>
        /// <param name="textContent"></param>
        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();
            }
        }
    }
}