You can define a FilenameFilter to match with file names and return true if the file name matches what you are looking for.
File dir = new File("/path/to/pdfs"); File[] files = dir.listFiles(new FilenameFilter() { @Override public boolean accept(File dir, String name) { return name.matches("Comp_20120619_[^_]*_2_632128_FC_A_8_23903.pdf"); } });
The listFiles() method returns an array of File objects. This makes sense because there can be more than one file that matches the pattern (theoretically, at least, although not necessarily on your system).
I used a regular expression to match a file name, using [^_]* to match a section you are not sure about. However, you can use any function that returns a boolean if the file name matches. For example, you can use startsWith and endsWith instead of the usual expression.
Martin ellis
source share