Here you can find the source of renameTo(File source, String newName)
Parameter | Description |
---|---|
source | The source file object. |
newName | The new name of the object. |
public static File renameTo(File source, String newName)
//package com.java2s; //License from project: Open Source License import java.io.File; public class Main { /**// w w w .j a v a2 s . c o m * Rename the file specified to the new name specified * in parameters.<br> * * @param source The source file object. * @param newName The new name of the object. * @return The new file object for the new path. */ public static File renameTo(File source, String newName) { if (!source.exists()) return null; String parentPath = source.getParent() == null ? "" : source.getParent(); File target = new File(parentPath, newName); boolean ret = source.renameTo(target); return ret ? target : null; } }