public static bool writeLineUser(String pathFile, List <User> content, bool flag) { System.IO.FileStream fs; if (!File.Exists(pathFile)) { var directory = Directory.CreateDirectory(Path.GetDirectoryName(pathFile)); fs = new System.IO.FileStream(pathFile, System.IO.FileMode.CreateNew); } else { fs = new System.IO.FileStream(pathFile, System.IO.FileMode.Append); } using (StreamWriter streamWriter = new StreamWriter(fs)) { try { for (int i = 0; i < content.Count; i++) { streamWriter.WriteLine(ConvertUserAndString.convertUserToString(content[i])); } } catch (Exception e) { Console.WriteLine(e.Message); return(false); } } return(true); }
public static List <User> readLineUser(String pathFile) { if (!File.Exists(pathFile)) { return(null); } List <User> content = new List <User>(); try { using (StreamReader streamReader = File.OpenText(pathFile)) { string item = ""; User user; while ((item = streamReader.ReadLine()) != null) { user = ConvertUserAndString.convertStringToUser(item); content.Add(user); } } } catch (Exception e) { Console.WriteLine(e.Message); return(new List <User>()); } return(content); }