java 判断是不是一个文件

import java.io.File;
import java.io.FileInputStream;
public class Lxi {
 public static void main(String[] args) {
  File f1 = new File("D:/Demo/ey/1.jpg");
  File f2 = new File("D:/Demo/ey1/1.jpg");
  try {
   FileInputStream fis1 = new FileInputStream(f1);
   FileInputStream fis2 = new FileInputStream(f2);
   if (fis1.available() != fis2.available()) {
   System.out.println(f1 + "和" + f2 +"不是同一文件");
   }else {
    while (fis1.read()== fis2.read()) {
     if (fis1.read()== -1|| fis2.read() == -1) {
      
      break;
     }
    }
    System.out.println(f1 +"和" + f2 +"是同一文件");
   }
  }catch(Exception e) {
   
  }
 }
}
posted @ 2020-06-10 08:53  信王勤宝  阅读(353)  评论(0编辑  收藏  举报