Java.io.File.hashCode() Method
Advertisements
Description
The java.io.File.hashCode() method computes and returns a hash code for this abstract name.
Declaration
Following is the declaration for java.io.File.hashCode() method −
public int hashCode()
Parameters
NA
Return Value
The method returns a hash code for this abstract pathname.
Exception
NA
Example
The following example shows the usage of java.io.File.hashCode() method.
package com.tutorialspoint; import java.io.File; public class FileDemo { public static void main(String[] args) { File f = null; int v; boolean bool = false; try { // create new file f = new File("C:\\test.txt"); // returns hash code for this abstract pathname v = f.hashCode(); // true if the file path exists bool = f.exists(); // if file exists if(bool) { // prints System.out.print("The hash code for this abstract pathname: "+v); } } catch(Exception e) { // if any error occurs e.printStackTrace(); } } }
Let us compile and run the above program, this will produce the following result −
The hash code for this abstract pathname: -246273912
java_io_file.htm
Advertisements