using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Leit.FrameWork
|
|
{
|
|
public partial class FileHelper
|
|
{
|
|
/// <summary>
|
|
/// 读取大文件
|
|
/// </summary>
|
|
/// <param name="filePath">文件路径</param>
|
|
/// <param name="encoding">文件编码格式</param>
|
|
/// <param name="fileReadLineAction">回调方法</param>
|
|
public static void ReadLong(string filePath, Encoding encoding, Action<string, int> fileReadLineAction)
|
|
{
|
|
int lineNum = 0;
|
|
using (StreamReader reader = new StreamReader(filePath, encoding))
|
|
{
|
|
string line;
|
|
while ((line = reader.ReadLine()) != null)
|
|
{
|
|
lineNum++;
|
|
fileReadLineAction.Invoke(line, lineNum);
|
|
}
|
|
fileReadLineAction.Invoke(line, -1);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 读取文件
|
|
/// </summary>
|
|
/// <param name="filePath">文件路径</param>
|
|
/// <param name="encoding">文件编码格式</param>
|
|
/// <returns></returns>
|
|
public static string Read(string filePath, Encoding encoding)
|
|
{
|
|
return File.ReadAllText(filePath, encoding);
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|