java - How to find file without extension -


i have uuid of file without extension

string uuid = "507f23e3-7634-42b6-8bef-df3eb87a595b" 

how find file has uuid , custom extension

how this:

public static void main(string[] args) {   jfilechooser c = new jfilechooser();   file dir = new file("directoryoffile");   final string uuid = "507f23e3-7634-42b6-8bef-df3eb87a595b";   dir.listfiles(new filenamefilter() {      @override      public boolean accept(file dir, string name)      {         // checks filename consisting of uuid custom extension         return name.startswith(uuid + ".");      }   }); } 

this of course match files looks this:

507f23e3-7634-42b6-8bef-df3eb87a595b.abc.def 

in case "abc" not part of extension, so, avoid (if desire), can replace startswith line with:

return name.startswith(uuid + ".") && name.lastindexof(".") == uuid.length(); 

the above checks last dot @ end of uuid.


Comments