0

我有检查这两个文件是否相似的功能。所以我做的一件事是比较文件的大小。我正在寻找一种比较文件内容并获得匹配百分比的方法。根据百分比值,我可以决定它们是否基本相等?

如果是文本文件,我正在阅读文本并计算差异。但是,如果它是一个 excel 或任何其他具有类似图像的文件怎么办?

4

1 回答 1

0

您可以尝试这样的事情,然后根据两个文件的比较做出决定。

Imports System.IO

Public Class FileSizeChecker

Public Sub FileChecker()

    Dim info As New FileInfo("test.txt")

    ' Get length of the file.
    Dim length As Long = info.Length

    ' Add more characters to the file.
    File.AppendAllText("test.txt", " More characters.")

    ' Get another file info.
    ' ... Then get the length.
    Dim info2 As New FileInfo("test.txt")
    Dim length2 As Long = info2.Length

    ' Show how the size changed.
    Console.WriteLine("Before and after: {0}, {1}", length, length2)
    Console.WriteLine("Size increase: {0}", length2 - length)

End Sub
于 2013-08-23T15:57:48.693 回答