java自学,怎么对这两个文本内容比较,如果一样就输出打印成功。到最后找不到方法名,不知道怎么比较



import java.io.FileInputStream;

public class Tiqu {
    public static void main(String[] args) {
        try {
            FileInputStream in = new FileInputStream("D:\\eclipse\\lianxi\\day19\\src\\day10\\haha1.txt");
            byte[] b = new byte[100];
            int len = 0;
            while ((len = in.read(b)) != -1) {
                System.out.println(new String(b, 0, len));
            }
            in.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        try {
            FileInputStream in1 = new FileInputStream("D:\\JAVA\\haha2.txt");
            byte[] b = new byte[100];
            int len = 0;
            while ((len = in1.read(b)) != -1) {
                System.out.println(new String(b, 0, len));
            }
            in1.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
if(in()=in1()){
    System.out.println("打印成功");
    }
}

package Test_;

import java.io.FileInputStream;
import java.io.IOException;

/**
 * @author yjx
 * @version 1.0
 */
public class Test2 {
    public static void main(String[] args) {
        StringBuilder str1= null;
        StringBuilder str2= null;
        FileInputStream in=null;
        try {
            in = new FileInputStream("D:\\JAVA\\haha2.txt");
            byte[] b = new byte[100];
            int len = 0;

            while ((len = in.read(b)) != -1) {
                assert false;
                str1.append(new String(b, 0, len));
            }
            in = new FileInputStream("D:\\eclipse\\lianxi\\day19\\src\\day10\\haha1.txt");
            while ((len = in.read(b)) != -1) {
                assert false;
                str2.append(new String(b, 0, len));
            }
           
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            if(in!=null){
                try {
                    in.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        if(str1.equals(str2)){
            System.out.println("打印成功");
        }
//      

    }


}


这里把这两个String保存出来,不要直接打印

img

Equals这两个String