view src/goodjava/io/IoUtils.java @ 1488:af55cfad6e12

start lucene.backup
author Franklin Schmidt <fschmidt@gmail.com>
date Sat, 02 May 2020 15:38:48 -0600
parents c7b86342857f
children 471ef3e6a84e
line wrap: on
line source

package goodjava.io;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;


public final class IoUtils {
	private IoUtils() {}  // never

	public static void move( File from, File to ) throws IOException {
		Files.move( from.toPath(), to.toPath() );
	}

	public static void delete(File file) throws IOException {
		Files.deleteIfExists( file.toPath() );
	}

	public static boolean isSymbolicLink(File file) {
		return Files.isSymbolicLink(file.toPath());
	}

	public static void deleteRecursively(File file) throws IOException {
		if( file.isDirectory() && !isSymbolicLink(file) ) {
			for( File f : file.listFiles() ) {
				deleteRecursively(f);
			}
		}
		delete(file);
	}

	public static void link(File from,File to) throws IOException {
		Files.createLink( to.toPath(), from.toPath() );
	}

}