70 lines
1.7 KiB
C#
70 lines
1.7 KiB
C#
|
|
using System.Collections.Generic;
|
|||
|
|
using System.IO;
|
|||
|
|
using System.Text;
|
|||
|
|
|
|||
|
|
namespace ZXKFramework
|
|||
|
|
{
|
|||
|
|
public class TextItem
|
|||
|
|
{
|
|||
|
|
StreamWriter writer;
|
|||
|
|
private string path;
|
|||
|
|
|
|||
|
|
public void SetTextPath(string path)
|
|||
|
|
{
|
|||
|
|
this.path = path;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public void SetTextPathAndClean(string path)
|
|||
|
|
{
|
|||
|
|
SetTextPath(path);
|
|||
|
|
Clean();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public void Clean()
|
|||
|
|
{
|
|||
|
|
if (path.IsNotNull()) return;
|
|||
|
|
FileInfo file = new FileInfo(path);
|
|||
|
|
if (file.Exists)
|
|||
|
|
{
|
|||
|
|
file.Delete();
|
|||
|
|
file.Refresh();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public void Write(string message)
|
|||
|
|
{
|
|||
|
|
Write(path, message);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//<2F>½<EFBFBD><C2BD>ı<EFBFBD><C4B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
void Write(string path, string message)
|
|||
|
|
{
|
|||
|
|
string dirPath = Path.GetDirectoryName(path);
|
|||
|
|
if (!Directory.Exists(dirPath))
|
|||
|
|
Directory.CreateDirectory(dirPath);
|
|||
|
|
FileInfo file = new FileInfo(path);
|
|||
|
|
if (!file.Exists)
|
|||
|
|
writer = file.CreateText();
|
|||
|
|
else
|
|||
|
|
writer = file.AppendText();
|
|||
|
|
writer.WriteLine(message);
|
|||
|
|
writer.Flush();
|
|||
|
|
writer.Dispose();
|
|||
|
|
writer.Close();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
public string Read()
|
|||
|
|
{
|
|||
|
|
if (path.IsNotNull()) return "";
|
|||
|
|
return File.ReadAllText(path, Encoding.UTF8);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//<2F>õ<EFBFBD>ÿ<EFBFBD><C3BF><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
|
|||
|
|
public string[] ReadAllLines()
|
|||
|
|
{
|
|||
|
|
if (path.IsNotNull()) return null;
|
|||
|
|
return File.ReadAllLines(path);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|