How to find files that match a wildcard string in Java?

前端 未结 16 1246
慢半拍i
慢半拍i 2020-11-22 10:52

This should be really simple. If I have a String like this:

../Test?/sample*.txt

then what is a generally-accepted way to get a list of fil

16条回答
  •  感动是毒
    2020-11-22 11:11

    Why not use do something like:

    File myRelativeDir = new File("../../foo");
    String fullPath = myRelativeDir.getCanonicalPath();
    Sting wildCard = fullPath + File.separator + "*.txt";
    
    // now you have a fully qualified path
    

    Then you won't have to worry about relative paths and can do your wildcarding as needed.

提交回复
热议问题