Home Tutorial Java Core Files Java file hashCode

 
 

Share on Google+Share on Google+
Java file hashCode
Posted on: April 14, 2006 at 12:00 AM
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
Advertisement

Related Tags for Java file hashCode:


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.

Posted on: April 14, 2006

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com