public static bool SaveByteFile(string path, byte[] content, Encoding encoding = null) { if (DirectoryHelper.CreateDirIfNotExist(FilePathHelper.GetDirectoryName(path))) { try { Encoding myencoding = encoding == null ? Encoding.UTF8 : encoding; using (FileStream fs = new FileStream(path, FileMode.OpenOrCreate)) { using (BinaryWriter sw = new BinaryWriter(fs, myencoding)) { sw.Write(content); sw.Flush(); return(true); } } } catch (System.Exception ex) { #if TEST_CODE UnityEngine.Debug.LogError(ex.Message); #endif } } return(false); }
public static bool CreateFile(string path) { if (Exists(path) == false) { try { if (string.IsNullOrEmpty(path)) { return(false); } DirectoryHelper.CreateDirIfNotExist(FilePathHelper.GetDirectoryName(path)); FileStream fs = File.Create(path); fs.Close(); return(true); } catch (System.Exception ex) { return(false); #if TEST_CODE UnityEngine.Debug.LogError(ex.Message); #endif } } return(true); }
public static bool MoveFile(string srcPath, string destPath) { if (Exists(srcPath)) { if (DirectoryHelper.CreateDirIfNotExist(FilePathHelper.GetDirectoryName(destPath))) { try { File.Move(srcPath, destPath); return(true); } catch (System.Exception ex) { #if TEST_CODE UnityEngine.Debug.LogError(ex.Message); #endif } } } return(false); }