Here you can find the source of renameFile(String oldname, String newname)
public static boolean renameFile(String oldname, String newname)
//package com.java2s; /*// ww w. ja v a2 s.co m * Copyright (C) 2001-2004 Gaudenz Alder * * 6/01/2006: I, Raphpael Valyi, changed back the header of this file to LGPL * because nobody changed the file significantly since the last * 3.0 version of GPGraphpad that was LGPL. By significantly, I mean: * - less than 3 instructions changes could honnestly have been done from an old fork, * - license or copyright changes in the header don't count * - automaticaly updating imports don't count, * - updating systematically 2 instructions to a library specification update don't count. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * */ import java.io.File; public class Main { public static boolean renameFile(String oldname, String newname) { try { // File (or directory) with old name File file = new File(oldname); // File (or directory) with new name File file2 = new File(newname); if (file2.exists()) { return false; } // Rename file (or directory) return file.renameTo(file2); } catch (Exception e) { System.out.println(e.getMessage()); e.printStackTrace(); return false; } } }