Java Rename File rename(File file, String prefix, String name, HashMap optional)

Here you can find the source of rename(File file, String prefix, String name, HashMap optional)

Description

rename

License

Open Source License

Declaration

public static void rename(File file, String prefix, String name, HashMap<String, String> optional) 

Method Source Code

//package com.java2s;
/**//from   w  w w  .  j av  a  2s  .  co m
 * Copyright (c) 2013, Robert Cherry * All rights reserved.
 *
 * This file is part of the Faust Engine.
 *
 * The Faust Engine is free software: you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the Free
 * Software Foundation, either version 3 of the License, or (at your option) any
 * later version.
 *
 * The Faust Engine 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 General Public License for more
 * details.
 *
 * You should have received a copy of the GNU General Public License along with
 * the Faust Engine. If not, see <http://www.gnu.org/licenses/>.
 */

import java.io.File;

import java.util.HashMap;

public class Main {
    public static void rename(File file, String prefix, String name, HashMap<String, String> optional) {

        // @note This will not rename directories
        if (file.isFile()) {

            //
            final String before = file.getName();
            final String shortName = prefix + file.getName();

            // Store it here
            optional.put(before, shortName);

            //
            file.renameTo(new File(name));
        }
    }
}

Related

  1. rename(File aFile, File dest)
  2. rename(File f1, File f2)
  3. rename(File file, String newName, boolean overwite)
  4. rename(File from)
  5. rename(File from, File to)
  6. rename(File from, File to)
  7. rename(File from, File to)