如何在Java中读取第一个和最后一个64kb的视频文件?

如何在Java中读取第一个和最后一个64kb的视频文件?,java,Java,我想使用字幕API。它需要视频文件的第一个和最后一个64kb的md5哈希。 我知道如何做md5部分只是想知道如何获得128kb的数据 Python中给出了一个API示例,但遗憾的是我不理解它 #this hash function receives the name of the file and returns the hash code def get_hash(name): readsize = 64 * 1024 with open(name, 'rb') as

我想使用字幕API。它需要视频文件的第一个和最后一个64kb的md5哈希。 我知道如何做md5部分只是想知道如何获得128kb的数据

Python中给出了一个API示例,但遗憾的是我不理解它

    #this hash function receives the name of the file and returns the hash code
def get_hash(name):
    readsize = 64 * 1024
    with open(name, 'rb') as f:
        size = os.path.getsize(name)
        data = f.read(readsize)
        f.seek(-readsize, os.SEEK_END)
        data += f.read(readsize)
    return hashlib.md5(data).hexdigest()


任何帮助都将不胜感激。

试试这样的方法

    FileInputStream in = new FileInputStream("d:/1.avi");
    byte[] a = new byte[64 * 1024];
    in.read(a);   //head
    long p = in.getChannel().size() - 64 * 1024;
    in.getChannel().position(p);
    in.read(a);   //tail

您想知道如何在Java中读取64kb的数据吗?可能是重复的。文件的前64kb和最后64kb。合并。请参见副本和副本中的链接。我认为这很简单。你一直说64kb,但你的代码示例读64kb。。。