Home > Backend Development > PHP Tutorial > java reads file name

java reads file name

巴扎黑
Release: 2023-03-02 16:48:02
Original
2560 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;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;
}

}


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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template