Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.IO;
- namespace PrzykladOdczytuZPliku
- {
- public class CustomFileReader
- {
- private List<string> list1;
- private List<string> list2;
- public CustomFileReader()
- {
- list1 = new List<string>();
- list2 = new List<string>();
- }
- public void ReadDataFromFile(string path)
- {
- using (var reader = new StreamReader(path))
- {
- try
- {
- while (reader.Peek() != 0)
- {
- ParseLine(reader.ReadLine());
- }
- }
- catch (Exception ex)
- {
- Console.WriteLine(ex.Message);
- }
- }
- }
- private void ParseLine(string readLine)
- {
- string[] tmp_line = readLine.Split('-');
- list1.Add(tmp_line[0]);
- list2.Add(tmp_line[1]);
- }
- public void SaveDataToFile(string path)
- {
- using (var writer = new StreamWriter(path))
- {
- try
- {
- for (int i = 0; i < list1.Count; i++)
- {
- var line = new StringBuilder();
- line.Append(list1[i]);
- line.Append('-');
- line.Append(list2[i]);
- writer.WriteLine(line);
- }
- }
- catch (Exception ex)
- {
- Console.WriteLine(ex.Message);
- }
- }
- }
- }
- public class Program
- {
- static void Main(string[] args)
- {
- var fileProcesor = new CustomFileReader();
- fileProcesor.ReadDataFromFile("plik.txt");
- fileProcesor.SaveDataToFile("plik2.txt");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement