⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 compfiles.java

📁 Mcgraw-Hill - Java 2 - A Beginner S Guide, 2Nd Ed - 2003 -prog.
💻 JAVA
字号:
/*   
   Project 10-1 
 
   Compare two files. 
 
   To use this program, specify the names   
   of the files to be compared on the command line. 
  
   java CompFile FIRST.TXT SECOND.TXT  
*/  
  
import java.io.*;  
  
class CompFiles {  
  public static void main(String args[])   
    throws IOException  
  {  
    int i=0, j=0;  
    FileInputStream f1;  
    FileInputStream f2;  
  
    try {  
      // open first file 
      try {  
        f1 = new FileInputStream(args[0]);  
      } catch(FileNotFoundException exc) {  
        System.out.println(args[0] + " File Not Found");  
        return;  
      }  
  
      // open second file  
      try {  
        f2 = new FileInputStream(args[1]);  
      } catch(FileNotFoundException exc) {  
        System.out.println(args[1] + " File Not Found");  
        return;  
      }  
    } catch(ArrayIndexOutOfBoundsException exc) {  
      System.out.println("Usage: CompFile f1 f2");  
      return;  
    }  
  
    // Compare files  
    try {  
      do {  
        i = f1.read();  
        j = f2.read();  
        if(i != j) break; 
      } while(i != -1 && j != -1);  
    } catch(IOException exc) {  
      System.out.println("File Error");  
    }  
    if(i != j)  
      System.out.println("Files differ."); 
    else 
      System.out.println("Files are the same."); 
  
    f1.close();  
    f2.close();  
  }  
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -