Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.io.IOException;
import java.nio.file.AtomicMoveNotSupportedException;
import java.nio.file.DirectoryNotEmptyException;
import java.nio.file.FileAlreadyExistsException;
import java.nio.file.Files;
import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;

public class Main {
    public static void main(String[] args) throws Exception {
        Path source = Paths.get("C:\\Java_Dev\\test1.txt");
        Path target = Paths.get("C:\\Java_Dev\\dir2\\test1.txt");

        try {
            Path p = Files.move(source, target, StandardCopyOption.ATOMIC_MOVE);
            System.out.println(source + "  has  been  moved to " + p);
        } catch (NoSuchFileException e) {
            System.out.println("Source/target does  not  exist.");
        } catch (FileAlreadyExistsException e) {
            System.out.println(target + "  already exists.  Move failed.");
        } catch (DirectoryNotEmptyException e) {
            System.out.println(target + "  is not  empty.  Move failed.");
        } catch (AtomicMoveNotSupportedException e) {
            System.out.println("Atomic move is not  supported. MOve  failed.");
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}