Example usage for java.nio.file NoSuchFileException printStackTrace

List of usage examples for java.nio.file NoSuchFileException printStackTrace

Introduction

In this page you can find the example usage for java.nio.file NoSuchFileException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:Main.java

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

    try {/*  w w w .ja  v a2 s  .c  o m*/
        Files.delete(p);
        System.out.println(p + "  deleted successfully.");
    } catch (NoSuchFileException e) {
        System.out.println(p + "  does  not  exist.");
    } catch (DirectoryNotEmptyException e) {
        System.out.println("Directory " + p + "  is not  empty.");
    } catch (IOException e) {
        e.printStackTrace();
    }

}

From source file:Main.java

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 {/*from w ww . j  av a  2  s.  c o m*/
        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();
    }

}

From source file:org.lizardirc.beancounter.Beancounter.java

public static void main(String[] args) {
    Path configurationFile = Paths.get("config.props");

    // Expect 0 or 1 arguments.  If present, argument is the location of the startup configuration file to use
    if (args.length > 1) {
        System.err.println("Error: Too many arguments.");
        System.err.println("Usage: java -jar beancounter.jar [configurationFile]");
        System.err.println("Where: configurationFile is the optional path to a startup configuration file.");
        System.exit(2);/*from w ww  .  j  a v a 2  s  .c om*/
    } else if (args.length == 1) {
        configurationFile = Paths.get(args[0]);
    }

    System.out.println("Reading configuration file " + configurationFile + "....");
    Properties properties = new Properties();
    try (InputStream is = Files.newInputStream(configurationFile)) {
        properties.load(is);
    } catch (NoSuchFileException e) {
        System.err.println("Error: Could not find configuration file " + configurationFile
                + " (NoSuchFileException). A default configuration file has been created for you at that location.");
        System.err.println(
                "The bot will now terminate to give you an opportunity to edit the configuration file.");
        try (InputStream defaultConfig = Beancounter.class.getResourceAsStream("/default.config.props")) {
            Files.copy(defaultConfig, configurationFile);
        } catch (IOException e1) {
            System.err.println("Error while writing out default configuration file.  Stack trace follows.");
            e1.printStackTrace();
        }
        System.exit(3);
    } catch (IOException e) {
        System.err.println("Error: Could not read configuration file " + configurationFile
                + ".  A stack trace follows.  The bot will now terminate.");
        e.printStackTrace();
        System.exit(3);
    }

    System.out.println("Creating bot....");
    Beancounter beancounter = new Beancounter(properties);

    System.out.println("Launching bot....");
    try {
        beancounter.run();
    } catch (Exception e) {
        System.err.println("Exception occurred launching bot: " + e.getMessage());
        System.err.println("Stack trace follows:");
        e.printStackTrace();
    }
}