Java file hashCode


 

Java file hashCode

This section demonstrates you the use of method hashCode().

This section demonstrates you the use of method hashCode().

Java file hashCode

This section demonstrates you the use of method hashCode().

Explanation:

A hashCode is a way of computing a small (32-bit) digest numeric key from a String or even an arbitrary clump of bytes. The method hashCode() of File class computes the hash code values of files and directories. It returns integer representations of the pathnames of files or directories.

Here is the code

import java.io.*;

public class FileHashCode {
	public static void main(String[] args) {
		File f = new File("C:/file.txt");
		int hcode = f.hashCode();
		System.out.println("Hash codes generated: " + hcode);
	}
}

Using the hashCode() method, you can compute the hash code values of files and directories.

Output:

Hash codes generated: 165084306

Ads