//读取违禁词文件 private void readFile() { FileStream fs = new FileStream(path, FileMode.Open); StreamReader sr = new StreamReader(fs); while (!sr.EndOfStream) { //读取一行数据进行处理 string line = sr.ReadLine().Trim(); //处理引号(删除后用空格作为分隔符分割数据) string content = line.Replace("\"", ""); //新建Message实例,然后添加到_forbidden变量 ForbiddenMessage message = new ForbiddenMessage(content); _forbiddenWords.Add(message); } sr.Close(); fs.Close(); }