获取指定目录下所有文件的名称
package demo;
import java.io.File;
/**
* Created by asus on 2017/2/9.
*/
public class FileName {
public static void main(String[] args) {
String path = "D://学习文件//开题";//指定打开文件的目录地址
getFile(path);
}
private static void getFile(String path){
// get file list where the path has
File file = new File(path);
// get the folder list
File[] array = file.listFiles();
for(int i=0;i<array.length;i++){
if(array[i].isFile()){
// only take file name
System.out.println("^^文件名^^^" + array[i].getName());
// take file path and name
System.out.println("##内容###" + array[i]);
// take file path and name
System.out.println("**路径***" + array[i].getPath());
}else if(array[i].isDirectory()){
getFile(array[i].getPath());
}
}
}
}