Home  >  Article  >  Backend Development  >  java reads file name

java reads file name

巴扎黑
巴扎黑Original
2016-12-01 10:32:042517browse

package read_dir;

import java.io.File;
import java.util.ArrayList;
import java.util.List;


public class ReadDirector {
private static String dir_name="D:\xunlei";
public static void main(String[] args) {
ReadDirector rd=new ReadDirector();
List filenames=rd.getFiles(dir_name);
for(int i =0;iString str=(String)filenames.get(i);
System.out.println("The file name of "+(i+1)+" is: "+str);
}
}

public List getFiles (String dirname){
File dir=new File(dirname);
File []files=dir.listFiles();
List file_names=new ArrayList();
for(int i=0;iif(files[i].isDirectory()){//Determine whether it is a directory
file_names.add(files[i].getName()+"=>It is a folder");
}
if(files[i].isHidden()){//Determine whether it is a hidden file
file_names.add(files[i].getName()+"=>It is a hidden text");
}
if (files[i].isFile()&&(!files[i].isHidden())){//Determine whether it is a file and it cannot be a hidden file
file_names.add(files[i].getName());
}
}
return file_names;
}

}


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn