總網頁瀏覽量

2015年10月4日 星期日

[Java] 指定目入下的檔案與目錄

import java.io.*;

public class Ex_File_2{
    public static void main(String args[]){
        String path = "c:/Program Files/Java/jdk1.8.0_25/";
        File f = new File(path);
        String[] filelist = f.list();
        for(int i = 0 ; i < filelist.length ; i++){           
            File f2 = new File(path + filelist[i]);
            if(f2.isDirectory()){
                System.out.println(filelist[i] + ": is Directory.");
            }else{
                System.out.println(filelist[i] + ": is File.");
            }
        }
    }
}


bin: is Directory.
COPYRIGHT: is File.
db: is Directory.
include: is Directory.
javafx-src.zip: is File.
jre: is Directory.
lib: is Directory.
LICENSE: is File.
README.html: is File.
release: is File.
src.zip: is File.
THIRDPARTYLICENSEREADME-JAVAFX.txt: is File.
THIRDPARTYLICENSEREADME.txt: is File.

沒有留言:

張貼留言