java 文件操作

来源:百度知道 编辑:UC知道 时间:2024/06/08 13:42:18
import java.io.FileInputStream;

public class a
{
private static int MAX_FILE_LENGTH = 1 * 1024 * 1024;
private static String inFileName1 = "C:\\1.txt";
private static String inFileName2 = "C:\\2.txt";

//这个函数是实现两个字符串的比较
public static String b(String str1,String str2)
{
......
}
public static void main(String[] args)
{
try
{
//Read the input file
FileInputStream inFile1 = new FileInputStream(inFileName1);
FileInputStream inFile2 = new FileInputStream(inFileName2);
byte[] buffer = new byte[MAX_FILE_LENGTH];
inFile1.read(buffer);
inFile2.read(buffer);
inFile1.close();
inFile2.close();

//Compare the file
String str = b();//这里想问一下,怎样把两个文件的内容传递给参数
System.out.print(str);
}
catch (Exception e)
{
System.out.print(e.toStr

inFile1.read(buffer);
inFile2.read(buffer);
inFile1.close();
inFile2.close();

//Compare the file
String str = b();
改为如下:
byte[] buffer1 = new byte[MAX_FILE_LENGTH];
byte[] buffer2 = new byte[MAX_FILE_LENGTH];

int rs1=inFile1.read(buffer1);
int rs2=inFile2.read(buffer2);
inFile1.close();
inFile2.close();

String str = b(new String(buffer1,0,rs1),new String(buffer,0,rs2));

以上我没有编译过,不过根据我的想法应该是这样,试试看吧,有问题再hi我