package cn.felay.io;
import java.io.IOException;
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
public class FileDemo {
public static void main(String[] args) {
String directoryName = "src/cn/felay/io";
// 获取某个目录的路径
Path path = Paths.get(directoryName);
DirectoryStream
director = null;
try {
//根据给定的目录创建一个文件集合
director = Files.newDirectoryStream(path,"*.{ini}");
for (Path path2 : director) {
System.out.println(path2.getFileName());
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if (director != null) {
try {
director.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
|