すると以下のように、あなたのプログラムを実行してみてください。 "C:"(ファイルファイル=新しい
import java.io.File;
import java.io.IOException;
public class TP {
public static void main(String[] args) throws IOException {
function5();
}
public static void function5() throws IOException {
File file = new File("c:\\");
if(file.isDirectory()){
System.out.println("It is a directory");
}
System.out.println("Absolute path is " + file.getAbsolutePath());
System.out.println("Canonical path is " + file.getCanonicalPath());
System.out.println("File path is " + file.getPath());
String[] strArr = file.list();
System.out.println(strArr.length);
for(String str : strArr){ System.out.println(str);
} }
}
はあなたが見つけるの場合は
1)ことファイル( "c:");)
絶対パスは現在のものですこのJavaプログラムをどこから実行しているのかを示します。以下の場合の駆動
2):
ワークスペースがCであるため、これは "C:\"(ファイルファイル=新しいファイル( "C:\");
絶対パスはC:ドライブです
ワークスペースがCにない場合:。。出力内容は同じになります
EDIT - canonical pathとabstract pathを追加しました.c:abstract pathはc:onlyであり、javaファイルの場所ではありません。
あなたは、異なるオペレーティングシステム上でプログラムを実行しますか? – Anand
いいえ、両方のウィンドウで –
あなたはどんな結果を得ていますか? – Anand