Example usage for java.nio.file Path toFile

List of usage examples for java.nio.file Path toFile

Introduction

In this page you can find the example usage for java.nio.file Path toFile.

Prototype

default File toFile() 

Source Link

Document

Returns a File object representing this path.

Usage

From source file:com.liferay.sync.engine.service.SyncAccountService.java

protected static void deleteSyncFiles(SyncAccount syncAccount) throws IOException {

    SyncFile syncFile = SyncFileService.fetchSyncFile(syncAccount.getFilePathName());

    SyncFileService.deleteSyncFile(syncFile, false);

    Path filePath = Paths.get(syncAccount.getFilePathName());

    if (!FileUtil.exists(filePath)) {
        return;/*ww  w. ja va  2  s. c  om*/
    }

    FileUtils.deleteDirectory(filePath.toFile());
}

From source file:edu.umd.umiacs.clip.tools.io.AllFiles.java

public static Stream<String> lines(Path path) {
    try {/*from   ww w  .  j a v a  2  s. c o  m*/
        String p = path.toString();
        if (!p.contains("*")) {
            return p.endsWith(".gz") ? GZIPFiles.lines(path)
                    : p.endsWith(".bz2") ? BZIP2Files.lines(path) : overridenLines(path);
        } else {
            File file = path.toFile();
            return Stream
                    .of(file.getParentFile().listFiles(
                            (dir, name) -> name.matches(file.getName().replace(".", "\\.").replace("*", ".+"))))
                    .sorted().flatMap(AllFiles::lines);
        }
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}

From source file:ch.bender.evacuate.RunnerCheckDirectoriesTest.java

/**
 * Executed at loading of this class (static inizalizer).
 * <p>/*from   www  .  j  a  v  a2s.  com*/
 * @throws Throwable
 *         On any problem
 */
@BeforeClass
public static final void doBeforeClass() throws Throwable {
    System.out.println("doBeforeClass() entering...");

    try {
        if (Files.exists(Testconstants.ROOT_DIR)) {
            Helper.deleteDirRecursive(Testconstants.ROOT_DIR);
        }

        Files.createDirectory(Testconstants.ROOT_DIR);

        Path orig = Testconstants.createNewFolder(Testconstants.ROOT_DIR, "orig");
        Path origSub1 = Testconstants.createNewFolder(orig, "sub1");
        Path origSub2 = Testconstants.createNewFolder(orig, "sub2");

        Path file1 = Testconstants.createNewFile(orig, "file1.txt");
        Path fileSub1 = Testconstants.createNewFile(origSub1, "fileSub1.txt");
        Path fileSub2 = Testconstants.createNewFile(origSub2, "fileSub2.txt");

        Path backup = Testconstants.createNewFolder(Testconstants.ROOT_DIR, "backup");
        FileUtils.copyDirectoryToDirectory(origSub1.toFile(), backup.toFile());
        FileUtils.copyDirectoryToDirectory(origSub2.toFile(), backup.toFile());
    } catch (Throwable e) {
        System.err.println("Throwable caught in doBeforeClass()");
        e.printStackTrace();
        throw e;
    }

    System.out.println("doBeforeClass() leaving...");
}

From source file:com.themodernway.server.core.io.IO.java

public static final boolean exists(final Path path) {
    return IO.exists(path.toFile());
}

From source file:com.themodernway.server.core.io.IO.java

public static final boolean isFile(final Path path) {
    return IO.isFile(path.toFile());
}

From source file:com.themodernway.server.core.io.IO.java

public static final boolean isFolder(final Path path) {
    return IO.isFolder(path.toFile());
}

From source file:com.themodernway.server.core.io.IO.java

public static final boolean isHidden(final Path path) {
    return IO.isHidden(path.toFile());
}

From source file:com.themodernway.server.core.io.IO.java

public static final boolean isReadable(final Path path) {
    return IO.isReadable(path.toFile());
}

From source file:com.themodernway.server.core.io.IO.java

public static final boolean isWritable(final Path path) {
    return IO.isWritable(path.toFile());
}

From source file:edu.umd.umiacs.clip.tools.io.AllFiles.java

public static Stream<CSVRecord> records(CSVFormat format, Path path) {
    try {/*  ww w.  j  a v a2 s  .  com*/
        String p = path.toString();
        if (!p.contains("*")) {
            return p.endsWith(".gz") ? GZIPFiles.records(format, path)
                    : p.endsWith(".bz2") ? BZIP2Files.records(format, path) : overridenRecords(format, path);
        } else {
            File file = path.toFile();
            return Stream
                    .of(file.getParentFile().listFiles(
                            (dir, name) -> name.matches(file.getName().replace(".", "\\.").replace("*", ".+"))))
                    .sorted().flatMap(f -> records(format, f));
        }
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}