title: Compare contents of two files line by line
body: <pre><code>public class MainActivity extends Activity {
  
  
      FileOutputStream fos;
      FileInputStream fOne, fTwo;
      ArrayList&lt;String&gt; arr1 = new ArrayList&lt;String&gt;();
      ArrayList&lt;String&gt; arr2 = new ArrayList&lt;String&gt;();
  
      ArrayList&lt;String&gt; words = new ArrayList&lt;String&gt;();
      ArrayList&lt;String&gt; wordsTwo = new ArrayList&lt;String&gt;();
      int count = 0;
      int countTwo = 0;
      int countThree = 0;
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          Button  fileOne = (Button)findViewById(R.id.file1);
          Button  fileTwo = (Button)findViewById(R.id.file2);
          Button  compare = (Button)findViewById(R.id.compare);
          arr1.add("1");
          arr1.add("2");
          arr1.add("3");
          arr1.add("4");
          //arr1.add("3");
  
          arr2.add("1");
          arr2.add("2");
  
  
          fileOne.setOnClickListener(new OnClickListener() {
  
              @Override
              public void onClick(View v) {
                  // TODO Auto-generated method stub
                  try
                  {
                      fos = openFileOutput("File1", Context.MODE_PRIVATE);
  
                      for(int temp = 0; temp&lt; arr1.size(); temp++)
                      {
                          fos.write((arr1.get(temp).getBytes()) );
                          fos.write(System.getProperty("line.separator").getBytes());
  
                      }
                      fos.close();
                      fos.flush();
  
                  }
  
                  catch(Exception e)
                  {
  
                  }
              }
          });
  
  
          fileTwo.setOnClickListener(new OnClickListener() {
  
              @Override
              public void onClick(View v) {
                  // TODO Auto-generated method stub
                  try
                  {
                      fos = openFileOutput("File2", Context.MODE_PRIVATE);
  
                      for(int temp = 0; temp&lt; arr2.size(); temp++)
                      {
                          fos.write((arr2.get(temp).getBytes()) );
                          fos.write(System.getProperty("line.separator").getBytes());
  
                      }
                      fos.close();
                      fos.flush();
  
                  }
  
                  catch(Exception e)
                  {
  
                  }
              }
          });
  
          compare.setOnClickListener(new OnClickListener() {
  
              @Override
              public void onClick(View v) {
                  // TODO Auto-generated method stub
                  try
                  {
                      fOne = openFileInput("File1");
                      fTwo = openFileInput("File2");
                  } catch (FileNotFoundException e) {
                      // TODO Auto-generated catch block
                      e.printStackTrace();
                  }
                  Scanner scanFile = new Scanner(new DataInputStream(fOne));
                  Scanner scanFileT = new Scanner(new DataInputStream(fTwo));
                  words = new ArrayList&lt;String&gt;();
                  wordsTwo = new ArrayList&lt;String&gt;();
  
                  while (scanFile.hasNextLine())
                  {
                      if(scanFile.nextLine()!=null)
                      {
                          count++;
                      }
  
                      while(scanFileT.hasNextLine())
                      {
                          if(scanFileT.nextLine()!=null)
                          {
                              countTwo++;
  
                          }
                      }
                  }
  
                  try 
                  {
                      fOne.close();
                      fTwo.close();
                      scanFile.close();
                      scanFileT.close();
                  } catch (IOException e) {
                      // TODO Auto-generated catch block
                      e.printStackTrace();
                  }
  
  
                  Toast.makeText(getBaseContext(), "One : " + count, 1000).show();
                  Toast.makeText(getBaseContext(), "Two : " + countTwo, 1000).show();
                  Toast.makeText(getBaseContext(), "Three : " + countThree, 1000).show();
                  count = 0 ;                         
                  countTwo = 0;
                  countThree = 0;
              }
          });
      }
  
  
  
  }
  </code></pre>
  
  <p>Above is the code to write and read the file. What I did here, write two files and read the contents..Now I have to compare contents of files line by line. What needs to be done? </p>