2 Star 2 Fork 0

zcy/StartTool

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
TextTools.cs 1.50 KB
一键复制 编辑 原始数据 按行查看 历史
sn78039 提交于 2022-09-26 12:22 +08:00 . 优化排序
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SccTools
{
public class TextFileUtil
{
private static string path=".\\path.text";
private TextFileUtil()
{
}
public static LinkedList<string> getTextLines(string textFilePath)
{
LinkedList<string> lines = new LinkedList<string>();
if (!File.Exists(path))
{
File.Create(path);
return lines;
}
try
{
using (StreamReader sr = new StreamReader(path))
{
string line;
while ((line = sr.ReadLine()) != null)
{
lines.AddLast(line);
}
}
}
catch (Exception e)
{
// ignored
}
return lines;
}
public static LinkedList<string> getTextLines()
{
return getTextLines(path);
}
public static void saveTextLines(List<string> lines)
{
if (!File.Exists(path))
{
File.Create(path);
}
using (StreamWriter sw = new StreamWriter(path))
{
foreach (string s in lines)
{
sw.WriteLine(s);
}
}
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C#
1
https://gitee.com/zcy_wxy/start-tool.git
git@gitee.com:zcy_wxy/start-tool.git
zcy_wxy
start-tool
StartTool
master

搜索帮助