Monday, 26 August 2013

Continue iteration of outer while loop

Continue iteration of outer while loop

I have to read data from two files. For that, I have to iterate these two
files using while. Here is my code...
// Data in File1 are A, B, C, D // Data in File2 are A, B,C
try
{
FileInputStream fOne = openFileInput("File1");
FileInputStream fTwo = openFileInput("File2");
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
Scanner scanFile = new Scanner(new DataInputStream(fOne));
Scanner scanFileT = new Scanner(new DataInputStream(fTwo));
while (scanFile.hasNextLine())
{
if(scanFile.nextLine()!=null)
{
count++;
Toast.makeText(getBaseContext(), "Count : " + count,
500).show();
}
while(scanFileT.hasNextLine())
{
if(scanFileT.nextLine()!=null)
{
countTwo++;
Toast.makeText(getBaseContext(), "CountTwo : " +
countTwo, 500).show();
}
}
}
I am using while loop. What I am getting here, first time count = 1 and
countTwo variable as 1, 2 and 3 and then again count variable as 2, 3, 4
(As data in file1 are 4 and in file2 are 3). Now I have to iterate outer
while loop such as I get count values as count=2 and countTwo= 1, 2, 3.
Again count=3 and countTwo = 1, 2, 3. Again count=4 and countTwo = 1, 2,
3. What needs to be done?

No comments:

Post a Comment