我必须从两个文件中读取数据。为此,我必须使用while迭代这两个文件。这里是我的代码...继续迭代外部while循环
//数据File1中的A,B,C,d //数据file2中有A,B,C
Scanner scanFile = new Scanner(new DataInputStream(fOne));
while (scanFile.hasNextLine())
{
countTwo = 0;
if(scanFile.nextLine()!=null)
{
count++;
Toast.makeText(getBaseContext(), "Count : " + count, 500).show();
}
else
scanFile.close();
Scanner scanFileT = new Scanner(new DataInputStream(fTwo));
while(scanFileT.hasNextLine())
{
if(scanFileT.nextLine()!=null)
{
countTwo++;
Toast.makeText(getBaseContext(), "CountTwo : " + countTwo, 500).show();
}
else
scanFileT.close();
}
}
我使用while循环。我在这里得到的第一次count = 1和countTwo变量为1,2和3,然后再次将变量计数为2,3,4(因为file1中的数据是4,而file2中的数据是3)。现在,我必须迭代outer while循环,例如count = 2和countTwo = 1,2,3。count count = 3和countTwo = 1,2,3.再次count = 4和countTwo = 1,2 ,3.需要做什么?
如果我正确理解您,您希望countTwo从1开始每次计数递增。如果是这样的话,我想你应该在进入内部循环之前分配countTwo = 1! – Ashish
其实,我必须在这里比较文件的内容。意思是,第一个文件的第一个内容将与第二个文件的所有内容匹配。同样,第一个文件的第二个内容将与第二个文件的所有内容相匹配,直到第一个文件的最后一个内容为止。 –
你的例子甚至没有编译。请提供你正在做什么的可运行示例。 –