how to rename file in java

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();
		}

	}
}
S‮uo‬rce:www.lautturi.com
Created Time:2017-09-28 17:29:45  Author:lautturi