Java File.list()方法

2019-10-16 22:16:22

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

public String [] list()

範例

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

import java.io.File;

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

    // create new file
    File f = new File("c:/Python3");

    // array of files and directory
    String[] paths = f.list();

    // for each name in the path array
    for (String path : paths) {
      System.out.println(path);
    }

  }
}

上面的程式碼生成以下結果。

DLLs
Doc
include
Lib
libs
LICENSE.txt
NEWS.txt
python.exe
python3.dll
python35.dll
pythonw.exe
README.txt
Scripts
tcl
Tools
vcruntime140.dll
worksp