📄 javashy46.java
字号:
/********************************************************************************************
第8章习题5
编写一个程序,比较两个文件是否相同。
********************************************************************************************/
import java.awt.*;
import java.util.*;
import java.applet.Applet;
import java.io.*;
public class Javashy46 extends Applet{
public static void main(String[] args) {
InputStream file1;
InputStream file2;
byte buffer1[];
byte buffer2[];
int fileSize1 = 0;
int fileSize2 = 0;
try {
file1 = new FileInputStream(args[0]);
file2 = new FileInputStream(args[1]);
fileSize1 = file1.available();
fileSize2 = file2.available();
buffer1 = new byte[fileSize1];
buffer2 = new byte[fileSize2];
if (fileSize1 != fileSize2) {
System.out.println("The two files are different!");
System.exit(0);
}
file1.read(buffer1);
file2.read(buffer2);
int cursor = 0;
while (cursor < fileSize1) {
if (buffer1[cursor] != buffer2[cursor]) {
System.out.println("The two files are different!");
System.exit(0);
}
cursor++;
}
System.out.println("The two files are the same");
}
catch (FileNotFoundException e) {
e.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -