比较文件 把2.txt里面包含1.txt的行过滤掉
直接上代码:
1string newhao = "";
2 string[] haoList1 = file1("1.txt", "\r\n");
3 string[] haoList2 = file1("2.txt", "\r\n");
4 DataTable dt = new DataTable();
5 dt.Columns.Add("hao", typeof(string));
6 for (int i = 1; i < haoList1.Length; i++)
7 {
8 DataRow dr = dt.NewRow();
9 dr["hao"] = haoList1[i];
10 dt.Rows.Add(dr);
11 }
12 haoList1 = null;
13 DataTable dt2 = new DataTable();
14 dt2.Columns.Add("hao", typeof(string));
15 for (int i = 1; i < haoList2.Length; i++)
16 {
17 DataRow dr = dt2.NewRow();
18 dr["hao"] = haoList2[i];
19 dt2.Rows.Add(dr);
20 }
21 haoList2 = null;
22 // string sql = "select* from dt where not exists(select 1 from dt2 where dt.yhao = dt2.ghao)";
23 var normalReceive = dt2.AsEnumerable().Except(dt.AsEnumerable(), DataRowComparer.Default);
24
25 foreach (var item in normalReceive)
26 {
27 label2.Text = (++x).ToString();
28 newhao += item["hao"].ToString()+"\r\n";
29
30 //lock (fileLock)
31 //{
32 if (x%10000==0)
33 {
34 using (StreamWriter sw = new StreamWriter("new1.txt", true))
35 {
36 sw.WriteLine(newhao);
37 }
38 newhao = "";
39 }
40 // }
41
42 }
43 using (StreamWriter sw = new StreamWriter("new1.txt", true))
44 {
45 sw.WriteLine(newhao);
46 }