Java Java File.listFiles()
方法具有以下語法。
public File [] listFiles()
在下面的程式碼顯示如何使用File.listFiles()
方法。
import java.io.File;
// At: W w W. y I i ba I.C o m
public class Main {
public static void main(String[] args) {
// create new file
File f = new File("c:/python3");
// returns pathnames for files and directory
File[] paths = f.listFiles();
// for each pathname in pathname array
for (File path : paths) {
System.out.println(path);
}
}
}
上面的程式碼生成以下結果。
c:\python3\DLLs
c:\python3\Doc
c:\python3\include
c:\python3\Lib
c:\python3\libs
c:\python3\LICENSE.txt
c:\python3\NEWS.txt
c:\python3\python.exe
c:\python3\python3.dll
c:\python3\python35.dll
c:\python3\pythonw.exe
c:\python3\README.txt
c:\python3\Scripts
c:\python3\tcl
c:\python3\Tools
c:\python3\vcruntime140.dll
c:\python3\worksp