Java-io-file-hashcode

提供:Dev Guides
移動先:案内検索

Java.io.File.hashCode()メソッド

説明

  • java.io.File.hashCode()*メソッドは、この抽象名のハッシュコードを計算して返します。

宣言

以下は* java.io.File.hashCode()*メソッドの宣言です-

public int hashCode()

パラメーター

NA

戻り値

メソッドは、この抽象パス名のハッシュコードを返します。

例外

NA

次の例は、java.io.File.hashCode()メソッドの使用法を示しています。

package com.finddevguides;

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