public void SaveToBinFile(String fileName, WordPosCollection dictFile) { Stream s = CSerialization.SerializeBinary(dictFile); s.Position = 0; CFile.WriteStream(fileName, (MemoryStream)s); }
/// <summary> /// 从文本文件读取字典 /// </summary> /// <param name="fileName"></param> public WordPosCollection LoadFromTextDict(String fileName) { WordPosCollection dictFile = new WordPosCollection(); String dictStr = CFile.ReadFileToString(fileName, "utf-8"); String[] words = CRegex.Split(dictStr, "\r\n"); foreach (String word in words) { String[] wp = CRegex.Split(word, @"\|"); if (wp == null) { continue; } if (wp.Length != 2) { continue; } int pos = 0; try { pos = int.Parse(wp[1]); } catch { continue; } WordPos dict = new WordPos(wp[0], pos); if (dict.Word.Contains("一") || dict.Word.Contains("二") || dict.Word.Contains("三") || dict.Word.Contains("四") || dict.Word.Contains("五") || dict.Word.Contains("六") || dict.Word.Contains("七") || dict.Word.Contains("八") || dict.Word.Contains("九") || dict.Word.Contains("十")) { dict.Pos |= (int)PosEnum.POS_A_M; } if (dict.Word == "字典") { dict.Pos = (int)PosEnum.POS_D_N; } dictFile.WordPosList.Add(dict); } return(dictFile); }
private CGetCurrentDir() { System.Diagnostics.Process p = System.Diagnostics.Process.GetCurrentProcess(); _ProcessDir = p.MainModule.FileName; _ProcessDir = CFile.GetPath(_ProcessDir); }