You made me read the manuals :) I solved a more general problem: how to replace any 2+ identical characters one by one with just one character:
String str = "assddffffadfdd..o"; System.out.println (str.replaceAll("(.)\\1+", "$1"));
Conclusion:
asdfadfd.o
If you only need a solution for the case of "filename .... ext", then I would prefer something simpler, as in Etaouin's answer, because it probably works faster (but not fact). My solution, simplified for this particular case, is as follows:
str.replaceAll("(\\.)\\1+", "$1")
Roman source share