Share on Google+Share on Google+

Java file hashCode

Advertisement
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

Advertisements

Posted on: April 14, 2006 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.