Java File.getPath()方法

2019-10-16 22:16:09

Java Java File.getPath()方法具有以下語法。

public String getPath()

範例

在下面的程式碼顯示如何使用File.getPath()方法。


import java.io.File;

public class Main {
  public static void main(String[] args) throws Exception {

    // create new files
    File f = new File("c:/asdf/");


    System.out.print(f.getPath());

  }
}

執行上面程式碼,得到以下結果 -

c:\asdf