Here you can find the source of renameFile(String currentPath, String newPath)
Parameter | Description |
---|---|
currentPath | currentPath/name of file |
newPath | new Path/name of file |
public static boolean renameFile(String currentPath, String newPath)
//package com.java2s; //License from project: LGPL import java.io.File; public class Main { /**//from www.j av a2 s. c om * Renames a file * * @param currentPath * currentPath/name of file * @param newPath * new Path/name of file * @return true if file was renamed, otherwise false */ public static boolean renameFile(String currentPath, String newPath) { boolean succeeded = false; try { File currentFile = new File(currentPath); if (currentFile.exists()) { File newFile = new File(newPath); succeeded = currentFile.renameTo(newFile); } } catch (Exception e) { e.printStackTrace(); } return succeeded; } /** * Determines whether specified path exists * * @param path * @return true if exists */ public static boolean exists(String path) { File file = new File(path); return file.exists(); } }