private void btnSaveToFile_Click(object sender, EventArgs e) { string appPath = Path.GetDirectoryName(Application.ExecutablePath); string fileName = "trie.txt"; string filePath = Path.Combine(appPath, fileName); trie.Save(filePath); }
/// <summary> /// 只考虑兼容原数据文件的情况,即采用高位在前 /// </summary> /// <param name="fs"></param> public void Save(FileStream fs) { var bs = ByteUtil.Int2Byte_HighFirst(id2tag.Length); fs.Write(bs, 0, bs.Length); for (int i = 0; i < id2tag.Length; i++) { bs = ByteUtil.UTF2Byte_HighFirst(id2tag[i]); fs.Write(bs, 0, bs.Length); } var ffs = _ffTrie.Values; bs = ByteUtil.Int2Byte_HighFirst(ffs.Length); fs.Write(bs, 0, bs.Length); for (int i = 0; i < ffs.Length; i++) { ffs[i].Save(fs); } _ffTrie.Save(fs); bs = ByteUtil.Int2Byte_HighFirst(_ftList.Count); fs.Write(bs, 0, bs.Length); for (int i = 0; i < _ftList.Count; i++) { _ftList[i].Save(fs); } if (_matrix != null) { var fstDimLen = _matrix.GetLength(0); bs = ByteUtil.Int2Byte_HighFirst(fstDimLen); fs.Write(bs, 0, bs.Length); for (int i = 0; i < fstDimLen; i++) { for (int j = 0; j < fstDimLen; j++) // 方阵 { bs = ByteUtil.Double2Byte_HighFirst(_matrix[i][j]); fs.Write(bs, 0, bs.Length); } } } else { fs.Write(new byte[4], 0, 4); } }