using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace CarManagerV2 { internal class SafeManager { public static void InitializeFile(string path) { if (!File.Exists(@path)) { using (StreamWriter writer = new StreamWriter(@path)) { // Create the file, empty writer.WriteLine(); } } } public static List ReadCars(string path) { List cars = new List(); using (StreamReader reader = new StreamReader(@path)) { string line; while ((line = reader.ReadLine()) != null) { // Process the line if (line == "") continue; cars.Add(Car.FromCsvString(line)); } } return cars; } public static void SaveCars(string path, List cars) { using (StreamWriter writer = new StreamWriter(@path)) { foreach (Car car in cars) { writer.WriteLine(car.ToCsvString()); } } } } }