public static List <UserInfoConfig> GetUserInfoByFile() { List <UserInfoConfig> listUsers = new List <UserInfoConfig>(); string filePath = @".\Config"; DirectoryInfo directory = new DirectoryInfo(filePath); if (!directory.Exists)//不存在 { return(null); } if (!File.Exists(filePath + @"\UserInfCofig.txt")) { return(null); } FileStream file = new FileStream(filePath + @"\UserInfCofig.txt", FileMode.Open, FileAccess.Read, FileShare.Read); StreamReader sr = new StreamReader(file, Encoding.Default); string reader = null; while ((reader = sr.ReadLine()) != null) { //过滤 if (reader == "" || reader == "\n") { continue; } // string[] Users = reader.Split(new char[] { ',' }); if (Users.Length < 7) { continue; } if (listUsers.Count >= 10) { return(listUsers); } UserInfoConfig uif = new UserInfoConfig(); uif.username = Users[0]; uif.password = Users[1]; uif.contractID = Users[2]; uif.valsign = Users[3]; uif.trade_addr_port = Users[4]; uif.market_addr_port = Users[5]; uif.http_addr_port = Users[6]; bool IsAdd = true; if (listUsers.Count > 0) { foreach (UserInfoConfig uerif in listUsers) { if (uif.username == uerif.username) { IsAdd = false; break; } } } if (IsAdd) { listUsers.Add(uif); } } sr.Close(); file.Close(); return(listUsers); }