Here you can find the source of renameToNextSequencedFile(String srcfile, String destfolder, String prefix, String suffix)
public static File renameToNextSequencedFile(String srcfile, String destfolder, String prefix, String suffix) throws Exception
//package com.java2s; //License from project: Open Source License import java.io.File; public class Main { private static String renameToNextSequencedFileLock = "renameToNextSequencedFile"; public static File renameToNextSequencedFile(String srcfile) throws Exception { return renameToNextSequencedFile(srcfile, null, null, null); }/* w ww . ja va 2 s .c om*/ public static File renameToNextSequencedFile(String srcfile, String destfolder, String prefix, String suffix) throws Exception { synchronized (renameToNextSequencedFileLock) { File src = new File(srcfile); File dest = null; int count = 0; if (destfolder == null) { if (src.getParent() != null) destfolder = src.getAbsoluteFile().getParent(); else destfolder = ""; } int pos; if (prefix == null) { if ((pos = srcfile.lastIndexOf('.')) != -1) { prefix = srcfile.substring(0, pos); if (suffix == null) suffix = srcfile.substring(pos); } } while (true) { dest = new File(destfolder + prefix + "_" + count++ + suffix); if (!dest.exists()) { break; } } if (!src.renameTo(dest)) throw new Exception("unable to rename " + src + " to " + dest); if (src.exists() && !src.delete()) src.deleteOnExit(); return dest; } } }