Java.io.File.hashCode() 方法
描述
java.io.File.hashCode() 方法计算并返回此抽象名称的哈希码。
声明
以下是 java.io.File.hashCode() 方法的声明 −
public int hashCode()
参数
NA
返回值
该方法返回此抽象路径名的哈希码。
异常
NA
示例
下面的例子展示了 java.io.File.hashCode() 方法的使用。
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();
}
}
}
让我们编译并运行上面的程序,这将产生下面的结果 −
The hash code for this abstract pathname: -246273912

