用Java搜索的文件

edi*_*233 1 java directory search file

因为上次我问了错误的问题,我想纠正我的意图.如何在指定文件夹中按名称查找文件?我有一个变量与此文件的名称,我想在指定的文件夹中找到它.有任何想法吗?

jac*_*bit 5

也许最简单的方法是:

String dirPath = "path/to/directory";
String fileName = "foo.txt";
boolean fileExistsInDir = new File( dirPath, fileName ).exists();
Run Code Online (Sandbox Code Playgroud)

文件只是文件系统中某个位置的占位符.该位置不一定存在.