12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.IO;
- namespace LYFZ.Software.MainBusiness.MultipleFileImport
- {
- public class FileUtil
- {
- public static bool CheckAndCreateDirectory(string dirPath)
- {
- try
- {
- if (!Directory.Exists(dirPath))
- {
- Directory.CreateDirectory(dirPath);
- }
- return true;
- }
- catch {
- return false;
- }
- }
- public static string ReadFile(string filePaht)
- {
- if (File.Exists(filePaht))
- {
- return File.ReadAllText(filePaht);
- }
- else
- {
- return "";
- }
- }
- public static void WriteFile(string filePath,string txt)
- {
- string dir = Path.GetDirectoryName(filePath);
- if(CheckAndCreateDirectory(dir))
- {
- File.WriteAllText(filePath, txt);
- }
- }
- public static void WriteFileAppend(string filePath, string txt)
- {
- string dir = Path.GetDirectoryName(filePath);
- if (CheckAndCreateDirectory(dir))
- {
- File.AppendAllText(filePath, txt);
- }
- }
- public static void WriteFileByASCII(string filePath, string txt)
- {
- string dir = Path.GetDirectoryName(filePath);
- if (CheckAndCreateDirectory(dir))
- {
- File.WriteAllText(filePath, txt, Encoding.ASCII);
- }
- }
- }
- }
|