Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package utils;
- import java.io.*;
- class compare {
- public static void main(String args[]) throws IOException {
- FileInputStream file1 = new InputStream(args[0]);
- FileInputStream file2 = new InputStream(args[1]);
- try {
- if(args.length != 2)
- throw (new RuntimeException("Usage : java compare <filetoread> <filetoread>"));
- while (true) {
- int a = file1.read();
- int b = file2.read();
- if (a==-1) {
- System.out.println("Both the files have same content");
- }
- else{
- System.out.println("Contents are different");
- }
- }
- }
- catch (IOException ioe) {
- System.out.println("Error: " + ioe);
- }
- catch (Exception e) {
- System.out.println("Error: " + e);
- }
- }
- }
- FileInputStream fin = new FileInputStream(args[i]);
- BufferedReader myInput = new BufferedReader
- (new InputStreamReader(fin));
- StringBuilder sb = new StringBuilder();
- while ((thisLine = myInput.readLine()) != null) {
- sb.append(thisLine);
- }
- import java.io.*;
- public class Testing {
- public static void main(String[] args) throws java.io.IOException {
- BufferedReader bfr2 = new BufferedReader(new InputStreamReader(
- System.in));
- String s1 = "";
- String s2 = "", s3 = "", s4 = "";
- String y = "", z = "";
- File file1 = new File("args[0]");
- File file2 = new File("args[1]");
- BufferedReader bfr = new BufferedReader(new FileReader(file1));
- BufferedReader bfr1 = new BufferedReader(new FileReader(file2));
- while ((z = bfr1.readLine()) != null)
- s3 += z;
- while ((y = bfr.readLine()) != null)
- s1 += y;
- System.out.println();
- System.out.println(s3);
- if (s3.equals(s1)) {
- System.out.println("Content of both files are same");
- } else {
- System.out.println("Content of both files are not same");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement