例子
以下示例显示java.io.File.hashCode()方法的用法。
package com.jc2182;
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