Example usage for java.nio.file FileAlreadyExistsException printStackTrace

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

Introduction

In this page you can find the example usage for java.nio.file FileAlreadyExistsException 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) {
    Path p1 = Paths.get("test.txt");
    try {/*from  w w w . ja  v  a 2 s. c om*/
        Files.createFile(p1);
        System.out.format("File created:  %s%n", p1.toRealPath());
    } catch (FileAlreadyExistsException e) {
        System.out.format("File %s  already exists.%n", p1.normalize());
    } catch (NoSuchFileException e) {
        System.out.format("Directory %s  does  not  exists.%n", p1.normalize().getParent());
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.bancvue.mongomigrate.CreateCommand.java

public int execute() {
    int exitCode = 0;
    Path file = null;//  w w w. j av a  2  s  .  co m
    try {
        // Ensure migrations folder exists.
        Path folder = Paths.get(migrationsFolder);
        if (!Files.exists(folder)) {
            Files.createDirectories(folder);
        }

        // Generate filename and ensure it doesn't already exist.
        file = Paths.get(migrationsFolder, generateMigrationFileName(migrationName));
        if (Files.exists(file))
            throw new FileAlreadyExistsException(file.toAbsolutePath().toString());

        // Write the file.
        BufferedWriter writer = Files.newBufferedWriter(file, Charset.forName("UTF-8"));
        writer.write("// Add migration javascript here.\n");
        writer.write("db.<collection_name>.update(\n");
        writer.write("    { <query> },\n");
        writer.write("    { <update> },\n");
        writer.write("    { multi: true }\n");
        writer.write(");\n");
        writer.flush();
        writer.close();

        System.out.println("Created migration file: " + file.toString());

    } catch (FileAlreadyExistsException e) {
        System.err.println("The specified migration file " + file.toString() + " already exists.");
        exitCode = 1;
    } catch (IOException e) {
        e.printStackTrace();
        exitCode = 1;
    }
    return exitCode;
}

From source file:com.spd.ukraine.lucenewebsearch1.web.IndexingController.java

@PostConstruct
public void init() {
    if (IS_DIRECTORY_IN_DISK) {
        String userDirectory = System.getProperty("user.dir");// + "/lucene"; 
        System.out.println("userDirectory " + userDirectory);
        Path userPath = Paths.get(userDirectory);
        Path rootPath = userPath.getRoot();
        String workingDirectory = rootPath.toString()
                .concat(System.getProperty("file.separator").equals("/")
                        ? userPath.subpath(0, 2).toString() + "/"
                        : "\\Users\\sf\\")
                .concat("luceneindex");
        System.out.println("workingDirectory " + workingDirectory);
        indexDir = new File(workingDirectory);
        try {//from w ww.  j av  a  2 s . co m
            Files.createDirectory(Paths.get(workingDirectory));
        } catch (FileAlreadyExistsException ex) {
            System.out.println("FileAlreadyExistsException");
        } catch (IOException ex) {
            //            System.out.println("IOException: " + ex.getMessage());
            ex.printStackTrace();
        }
        if (null == indexDir) {
            return;
        }
        try {
            directory = FSDirectory.open(indexDir);
        } catch (IOException ex) {
            System.out.println("IOException: " + ex.getMessage());
        }
    } else {
        directory = new RAMDirectory();
    }
    analyzer = new StandardAnalyzer(Version.LUCENE_43);//new StandardAnalyzer();
    IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_43, analyzer);
    try {
        indexWriter = new IndexWriter(directory, config);
    } catch (IOException ex) {
        //            ex.printStackTrace();
        //            return;
    }
}