while (sr1.Peek()>0)
            {
                str1 = sr1.ReadLine();
                MessageBox.Show("sr1"+str1);
                while (sr2.Peek()>0)
                {
                    str2 = sr2.ReadLine();
                    str3 = str2.Substring(5);
                    MessageBox.Show("sr2"+str3);
                    if (str1.Equals(str3) == true)
                    {
                        MessageBox.Show("hello");
                        str1 = str1 + str2.Substring(0,5);
                        sw.WriteLine(str1); 
                    }
                  
                }
            }
问题:第一次循环的时候可以进入到第二个while中,以后就不能了,不知道为什么

解决方案 »

  1.   

    sr1
    sr2是什么都不知道~~
    叫我们怎么看
      

  2.   

    Peek函数能用么?我的映像中好像只能用ReadLine然后判断PositionSr1和Sr2是StreamReader么?
      

  3.   

    StreamReader中Peek到最后就返回-1  能用
    不知道sr1 sr2读的是什么怎么看?
      

  4.   

    sr1,sr2是两个流文件,读入两个 文本,然后比较两个文本中的内容,有相同的 则提出来
      

  5.   

    都改成 .Peek() >= 0 试试
      

  6.   

    while (sr2.Peek()>0)
                    {
                        str1 = sr1.ReadLine();  ???            
                        str2 = sr2.ReadLine();
                        str3 = str2.Substring(5);
      

  7.   

    StreamReader read1 = new StreamReader (@"c:\1.txt");
           StreamReader read2 = new StreamReader(@"c:\3.txt");
            ArrayList aList1 = new ArrayList();
            ArrayList aList2 = new ArrayList();
            while(read1.Peek() > 0)
            {
                aList1.Add(read1.ReadLine());
            }
            while (read2.Peek() > 0)
            {
                aList2.Add(read2.ReadLine());  
            }
            for (int i = 0; i < aList1.Count; i++)
            {
                for (int j = 0; j < aList2.Count; j++)
                {
                    if(aList1[i].ToString().Equals(aList2[j].ToString()))
                    {
                        Response.Write(aList1[i].ToString()+"<br>");
                        break;
                    }
                }
            }