public static void Save(IByteUtilizer saveItem, string folderName, string fileName, bool overwrite = true) { string prefix = Application.persistentDataPath + "/"; string folderPath = prefix + folderName; string filePath = folderPath + "/" + fileName; if (!overwrite && File.Exists(filePath)) { Debug.LogError("[overwrite: false] File exists! Did not attempt to overwrite"); return; } if (!Directory.Exists(folderPath)) { Directory.CreateDirectory(folderPath); } var writer = new ByteUtility.Writer(); writer.Add(saveItem); var bytes = writer.Buffer; var stream = new FileStream(filePath, FileMode.Create, FileAccess.Write); stream.Write(bytes, 0, bytes.Length); stream.Dispose(); stream.Close(); }
public static void Save(IByteUtilizer saveItem, string path) { var writer = new ByteUtility.Writer(); writer.Add(saveItem); var bytes = writer.Buffer; var stream = new FileStream(path, FileMode.Create); stream.Write(bytes, 0, bytes.Length); stream.Dispose(); stream.Close(); }