java reads file name

巴扎黑
Release: 2023-03-02 16:48:02
Original
2486 people have browsed it

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;i String 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;i if(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;
}

}


Related labels:
source:php.cn
Statement of this Website
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!