public static void main(String[] args) {
        if (args.length != 2) {
            System.err.println("Usage: java TextComparer <file name> <file name>");
            System.exit(-1);
        }

        BufferedReader reader1 = null;
        BufferedReader reader2 = null;

        try {
            reader1 = new BufferedReader(new FileReader(args[0]));
        } catch (IOException ioe) {
            System.err.println("Cannot open " + args[0]);
            System.exit(-1);
        }

        try {
            reader2 = new BufferedReader(new FileReader(args[1]));
        } catch (IOException ioe) {
            System.err.println("Cannot open " + args[1]);
            System.exit(-1);
        }

        String line1, line2;
        int count = 0;

        try {
            while ((line1 = reader1.readLine()) != null) {

                line1 = removeSpaces(line1);

                line2 = reader2.readLine();

                if (line2 == null) {
                    System.out.println("Second file is shorter (only " + count + " lines)");
                    System.exit(-1);
                }
                else {
                    line2 = removeSpaces(line2);
                    if (!line1.equals(line2)) {
                        System.out.println("Comparison failure in line " + count + ":");
                        System.out.println(line1);
                        System.out.println(line2);
                        System.exit(-1);
                    }
                }

                count++;
            }

            if (reader2.readLine() != null) {
                System.out.println("First file is shorter (only " + count + " lines)");
                System.exit(-1);
            }
        } catch (IOException ioe) {
            System.err.println("IO error while reading files");
            System.exit(-1);
        }

        try {
            reader1.close();
            reader2.close();
        } catch (IOException ioe) {
            System.err.println("Could not close files");
            System.exit(-1);
        }

        System.out.println("Comparison ended successfully");
    }