FileContrast - int lc1 = 1 int lc2 = 1 contrast all lines...

Info icon This preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
//********************************************************************* // FileContrast.java Author: Lewis and Loftus // // Solution to Programming Project 8.6. //********************************************************************* import java.io.*; import java.util.*; public class FileContrast { //----------------------------------------------------------------- // Contrasts two text files. //----------------------------------------------------------------- public static void main (String [] args) { try { BufferedReader in1 = new BufferedReader ( new FileReader ( new File (args[0]))); BufferedReader in2 = new BufferedReader ( new FileReader ( new File (args[1]))); String ln1 = in1.readLine(); String ln2 = in2.readLine();
Image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: int lc1 = 1; int lc2 = 1; // contrast all lines until one end of file while ((ln1 != null) && (ln2 != null)) { if (! ln1.equals(ln2)) System.out.println ("1(" + lc1 + "): " + ln1 + "\n" + "2(" + lc2 + "): " + ln2); ln1 = in1.readLine(); ln2 = in2.readLine(); lc1++; lc2++; } // print all lines of the remaining file (if any) if (ln1 == null) while (ln2 != null) { System.out.println ("2(" + lc2 + "): " + ln2); ln2 = in2.readLine(); lc2++; } else while (ln1 != null) { System.out.println ("1(" + lc1 + "): " + ln1); ln1 = in1.readLine(); lc1++; } } catch (Exception ex) { ex.printStackTrace (System.err); System.out.println ("Usage: java FileContrast file1 file2"); } } }...
View Full Document

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern