how to rename file in java/**
* @author lautturi.com
* Java example: rename a file using java
*/
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.*;
public class Lautturi {
public static void main(String[] args) {
Path source = Paths.get("/path/to/testfile.txt");
Path target = Paths.get("/path/to/newfile.txt");
try {
Files.move(source, target);
} catch (IOException e) {
e.printStackTrace();
}
}
}
Suorce:www.lautturi.com