String (String filename) { File f = new File(filename); if (! f.exists()) return filename; int dot = filename.lastIndexOf('.'); // we believe file has some ext. For instance, ".wsdl" String name = filename.substring(0, dot); String ext = filename.substring(dot); int num = 0; do { f = new File(name + ++num + ext); } while (f.exists()); return name + num + ext; }