Вытяг из проекта "FDF" - функция сравнивает два файла и отличия записывает в третий

...

 void get_del_friend() {
       
        int n=0;
            string friend;
            StreamWriter sw_t1;
            StreamWriter sw = new StreamWriter("del.dat");
            StreamReader sw_t;
            StreamReader fr_d;
            StreamReader fr;
            string str="";


            try
            {//MessageBox.Show("1");
                fr = new StreamReader("friend.dat", Encoding.UTF8);
               
                while (fr.Peek() != -1)
                {
                    friend = fr.ReadLine();
                    fr_d = new StreamReader("friend_del.dat", Encoding.UTF8);
                    n = 0;
                    while (fr_d.Peek() != -1)
                    {
                        if (friend == fr_d.ReadLine()) n += 1;
                    }
                   
                    if (n == 0) {
                       
                        str += friend;
                        str += "\n";                    
                         }
                    fr_d.Close();
                }

                sw_t = new StreamReader("del_temp.dat");
                while (sw_t.Peek() != -1)
                {
                    str += sw_t.ReadLine();
                    str += "\n";
                    }
               
               
                sw.WriteLine(str);
                sw_t.Close();
                sw_t1 = new StreamWriter("del_temp.dat");
                sw_t1.WriteLine(str);
                sw_t1.Close();

                //MessageBox.Show(str);
               
                sw.Close();
                fr.Close();
            }
            catch { }


            StreamReader frd = new StreamReader("friend_del.dat", Encoding.UTF8);
            sw = new StreamWriter("friend.dat");

            while (frd.Peek() != -1)
            {
                sw.WriteLine(frd.ReadLine());
            }
            sw.Close();
            frd.Close();
       
        }
....

Комментарии

Популярные сообщения