70 lines
1.7 KiB
C#
70 lines
1.7 KiB
C#
using System.IO;
|
|
namespace SMHFramework.Helper
|
|
{
|
|
public static class IOHelper
|
|
{
|
|
public static void CheckFolder(string path)
|
|
{
|
|
if (!string.IsNullOrEmpty(path))
|
|
{
|
|
if (!Directory.Exists(path))
|
|
{
|
|
Directory.CreateDirectory(path);
|
|
}
|
|
}
|
|
}
|
|
|
|
public static void CheckFile(string path)
|
|
{
|
|
if (!File.Exists(path))
|
|
{
|
|
File.Create(path).Dispose();
|
|
}
|
|
}
|
|
|
|
public static void Write2File(string content, string path)
|
|
{
|
|
CheckFile(path);
|
|
File.WriteAllText(path, content);
|
|
}
|
|
|
|
public static void Write2File(byte[] content, string path)
|
|
{
|
|
CheckFile(path);
|
|
File.WriteAllBytes(path, content);
|
|
}
|
|
|
|
public static void Write2File(string[] contents, string path)
|
|
{
|
|
CheckFile(path);
|
|
File.WriteAllLines(path, contents);
|
|
}
|
|
|
|
public static string ReadStringFormFile(string path)
|
|
{
|
|
CheckFile(path);
|
|
var str = File.ReadAllText(path);
|
|
return str;
|
|
}
|
|
|
|
public static string[] ReadStringArrayFormFile(string path)
|
|
{
|
|
CheckFile(path);
|
|
var str = File.ReadAllLines(path);
|
|
return str;
|
|
}
|
|
|
|
public static byte[] ReadBytesFormFile(string path)
|
|
{
|
|
CheckFile(path);
|
|
var bytes = File.ReadAllBytes(path);
|
|
return bytes;
|
|
}
|
|
|
|
public static string GetPath(params string[] pathParams)
|
|
{
|
|
return Path.Combine(pathParams);
|
|
}
|
|
}
|
|
}
|