using System.IO;
public static class FileManager
{
///
/// 读取文件
///
/// 文件路径
///
public static string ReadFile(string filePath)
{
if (!File.Exists(filePath))
{
WriteFile("[]", filePath);
return "[]";
}
return File.ReadAllText(filePath);
}
///
/// 写入文件
///
/// 写入的内容
/// 写入路径
public static void WriteFile(string str, string filePath)
{
if (Directory.Exists(filePath) == false)
{
DirectoryInfo pathInfo = new DirectoryInfo(filePath);
pathInfo.Parent.Create();
}
File.WriteAllText(filePath, str);
}
///
/// 检查文件路径
///
///
///
public static string CalFilePath(string path)
{
if (path.Contains("\\"))
{
path = path.Replace("\\", "/");
}
return path;
}
}