public int renameFile(String file, String toFile) { File toBeRenamed = new File(file); if ((!(toBeRenamed.exists())) || (toBeRenamed.isDirectory())) { System.out.println("File does not exist: " + file); return 0; } File newFile = new File(toFile); if (toBeRenamed.renameTo(newFile)) { System.out.println("File has been renamed."); return 1; } System.out.println("Error renmaing file"); return -1; }