Java-io-file-getabsolutepath
提供:Dev Guides
Java.io.File.getAbsolutePath()メソッド
説明
- java.io.File.getAbsolutePath()*メソッドは、この抽象パス名の絶対パス名文字列を返します。
宣言
以下は* java.io.File.getAbsolutePath()*メソッドの宣言です-
public String getAbsolutePath()
パラメーター
NA
戻り値
このメソッドは、同じファイルまたはディレクトリを示す絶対パス名を返します。
例外
*SecurityException* -システムプロパティ値にアクセスできない場合。
例
次の例は、java.io.File.getAbsolutePath()メソッドの使用法を示しています。
package com.finddevguides;
import java.io.File;
public class FileDemo {
public static void main(String[] args) {
File f = null;
String path = "";
boolean bool = false;
try {
//create new files
f = new File("test.txt");
//returns true if the file exists
bool = f.exists();
//if file exists
if(bool) {
//get absolute path
path = f.getAbsolutePath();
//prints
System.out.print("Absolute Pathname "+ path);
}
} catch(Exception e) {
//if any error occurs
e.printStackTrace();
}
}
}
上記のプログラムをコンパイルして実行すると、次の結果が生成されます-
Absolute Path D:\EclipseAndroid\IO\BufferedInputStream\test.txt