public void SerializableSave(GamesDataSet chEnData) { string fileDirectory = Environment.CurrentDirectory + "\\"; if (!Directory.Exists(fileDirectory)) { Directory.CreateDirectory(fileDirectory); } string fileName = "ChEnData.dat"; Stream stream = new FileStream(fileDirectory + fileName, FileMode.Create, FileAccess.ReadWrite); BinaryFormatter binaryFormatter = new BinaryFormatter(); binaryFormatter.Serialize(stream, chEnData); stream.Close(); }
/// <summary> /// 反序列化翻译数据文件 /// </summary> /// <returns>返回序列化的成功与否</returns> private bool LoadChEnData() { string path = Environment.CurrentDirectory + "\\ChEnData.dat"; if (!File.Exists(path)) { return(false); } try { Stream stream = new FileStream(path, FileMode.Open, FileAccess.Read); BinaryFormatter binaryFormatter = new BinaryFormatter(); CHENDATA = (GamesDataSet)binaryFormatter.Deserialize(stream); stream.Close(); return(true); } catch (Exception) { return(false); } }