Here you can find the source of rename(String srcFilename, String destFilename)
Parameter | Description |
---|---|
srcFilename | old filename |
destFilename | new filename |
public static boolean rename(String srcFilename, String destFilename)
//package com.java2s; //License from project: Open Source License import java.io.*; public class Main { /**// ww w . ja v a2s.c om * renames a file to the new filename * * @param srcFilename * old filename * @param destFilename * new filename * @return true if success, otherwise false */ public static boolean rename(String srcFilename, String destFilename) { File srcFile; File destFile; boolean result = false; srcFile = new File(srcFilename); destFile = new File(destFilename); try { result = srcFile.renameTo(destFile); } catch (Exception e) { System.err.println("failed to rename file: " + e.toString()); // e.printStackTrace(); } finally { srcFile = null; destFile = null; } return result; } }