commons-file/src/main/java/info/monitorenter/util/FileUtil.java
public static String getDefaultFileName(final String name) {
    String result;
    File f = new File(name);
    if (!f.exists()) {
      result = f.getAbsolutePath();
    } else {
      final Map.Entry<String, String> cut = FileUtil.cutExtension(name);
      final String prefix = cut.getKey();
      final String suffix = cut.getValue();
      int num = 0;
      while (f.exists()) {
        f = new File(prefix + '_' + num + '.' + suffix);
        num++;
      }
      result = f.getAbsolutePath();
    }
    return result;
  }
public static String getDefaultFileName(final String name) {
    String result;
    File f = new File(name);
    if (!f.exists()) {
      result = f.getAbsolutePath();
    } else {
      final Map.Entry<String, String> cut = FileUtil.cutExtension(name);
      final String prefix = cut.getKey();
      final String suffix = cut.getValue();
      int num = 0;
      while (f.exists()) {
        f = new File(prefix + '_' + num + '.' + suffix);
        num++;
      }
      result = f.getAbsolutePath();
    }
    return result;
  }
public static String getDefaultFileName ( final String name ) { String result ; File f = new File ( name ) ; if ( ! f . exists ( ) ) { result = f . getAbsolutePath ( ) ; } else { final Map . Entry < String , String > cut = FileUtil . cutExtension ( name ) ; final String prefix = cut . getKey ( ) ; final String suffix = cut . getValue ( ) ; int num = 0 ; while ( f . exists ( ) ) { f = new File ( prefix + ' ' + num + ' ' + suffix ) ; num ++ ; } result = f . getAbsolutePath ( ) ; } return result ; }
Finds a filename based on the given name. If a file with the given name
does not exist, <tt>name</tt> will be returned.
<p>

Else:

<pre>
&quot;myFile.out&quot;     --&gt; &quot;myFile_0.out&quot;
&quot;myFile_0.out&quot;   --&gt; &quot;myFile_1.out&quot;
&quot;myFile_1.out&quot;   --&gt; &quot;myFile_2.out&quot;
....
</pre>

<p>

The potential extension is preserved, but a number is appended to the
prefix name.
<p>

@param name
A desired file name.

@return A String that sticks to the naming convention of the given String
but is unique in the directory scope of argument <tt>name</tt>.
Finds a filename based on the given name . If a file with the given name does not exist <tt > name< / tt > will be returned . <p >