现在的位置: 首页 > 综合 > 正文

两文件内容比较

2013年01月31日 ⁄ 综合 ⁄ 共 872字 ⁄ 字号 评论关闭
/*public static boolean compareTwoFile(String filePath1, String filePath2) {
		File file1 = new File(filePath1);
		File file2 = new File(filePath2);
		FileInputStream fileis1 = null;
		try {
			fileis1 = new FileInputStream(file1);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
		FileInputStream fileis2 = null;
		try {
			fileis2 = new FileInputStream(file2);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
		FileChannel fileChannel1 = fileis1.getChannel();
		FileChannel fileChannel2 = fileis2.getChannel();

		MappedByteBuffer mappedByteBuffer1 = null;
		MappedByteBuffer mappedByteBuffer2 = null;
		try {
			mappedByteBuffer1 = fileChannel1.map(FileChannel.MapMode.READ_ONLY,
					0, file1.length());
		} catch (IOException e) {
			e.printStackTrace();
		}
		try {
			mappedByteBuffer2 = fileChannel2.map(FileChannel.MapMode.READ_ONLY,
					0, file2.length());
		} catch (IOException e) {
			e.printStackTrace();
		}
		if ((mappedByteBuffer1.compareTo(mappedByteBuffer2)) != 0) {
			return false;
		}
		return true;
	}*/

抱歉!评论已关闭.