目录

int hashCode()

描述 (Description)

java.io.File.hashCode()方法计算并返回此抽象名称的哈希码。

声明 (Declaration)

以下是java.io.File.hashCode()方法的声明 -

public int hashCode()

参数 (Parameters)

NA

返回值 (Return Value)

该方法返回此抽象路径名的哈希码。

异常 (Exception)

NA

例子 (Example)

以下示例显示了java.io.File.hashCode()方法的用法。

package com.iowiki;
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
↑回到顶部↑
WIKI教程 @2018