Java File Rename renameFile(File file, String newName)

Here you can find the source of renameFile(File file, String newName)

Description

rename File

License

Apache License

Declaration

public static void renameFile(File file, String newName) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.io.File;

public class Main {
    public static void renameFile(File file, String newName) {
        if (file == null)
            throw new NullPointerException("file must not be null");
        if (!file.isFile() || !file.exists())
            throw new IllegalArgumentException("file must not be a file and exists");
        File newFile = new File(file.getParent() + "/" + newName);
        file.renameTo(newFile);/*from  w  w w  .  jav a 2s . c  o  m*/
    }
}

Related

  1. renameFile(File file, String ext)
  2. renameFile(File file, String name)
  3. renameFile(File file, String newFilename)
  4. renameFile(File file, String newName)
  5. renameFile(File file, String newName)
  6. renameFile(File file, String newName)
  7. renameFile(File file, String sign, String suffix)