FileContrast - int lc1 = 1; int lc2 = 1; // contrast all...

Info iconThis 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();
Background image of page 1

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

View Full DocumentRight Arrow Icon
Background 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

This note was uploaded on 05/17/2011 for the course COP 3530 taught by Professor Davis during the Spring '08 term at University of Florida.

Page1 / 2

FileContrast - int lc1 = 1; int lc2 = 1; // contrast all...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online