运行前提:保存三个文本文件“text1.txt”、“text2.txt”、“text3.txt”到存放“IOOperation.java”的同一个文件夹中。其中两个文本文件内容相同,一个不同于其他两个。
运行方法:在命令行提示符模式下cd到“IOOperation.java”所在文件夹,编译命令“javac IOOperation.java”,编译成功后输入“java IOOperation text1.txt text2.txt”就好了。更详细的信息可以看代码。
// Filename: IOOperation.java
import java.io.*;
class IOOperation
{
public static void main(String[] args)
{
FileInputStream File1 = null;
FileInputStream File2 = null;
BufferedReader in = null;
String sFile;
if(args.length != 2)
{
System.out.println("The command line should be: java IOOperation testX.txt testX.txt");
System.out.println("X should be one of the array: 1, 2, 3");
System.exit(0);
}
try
{
File1 = new FileInputStream(args[0]);
File2 = new FileInputStream(args[1]);
//输出两个文件
try
{
//输出文件1
in = new BufferedReader(new FileReader(args[0]));
System.ou