Example usage for java.io File getParent

List of usage examples for java.io File getParent

Introduction

In this page you can find the example usage for java.io File getParent.

Prototype

public String getParent() 

Source Link

Document

Returns the pathname string of this abstract pathname's parent, or null if this pathname does not name a parent directory.

Usage

From source file:Main.java

/** Copy files or folders */
public static boolean copyFiles(File srcFile, File dstFile) {
    boolean ret = true;

    if (srcFile.getParent().equals(dstFile)) {
        return false;
    }//from   www .ja v a2s  .c  om

    if (srcFile.isDirectory()) {
        if (dstFile.getPath().indexOf(srcFile.getPath()) == 0) {
            return false;
        } else {
            if (copyDir(srcFile, dstFile) == false) {
                return false;
            }
        }
    } else {
        ret = copyFile(srcFile, dstFile);
    }

    return ret;
}

From source file:org.hdl.tensorflow.yarn.util.Utils.java

public static String getParentDir(String path) {
    File file = new File(path);
    return file.getParent();
}

From source file:fr.insalyon.creatis.vip.applicationimporter.server.business.TargzUtils.java

private static void addFileToTarGz(TarArchiveOutputStream tOut, File f, String dir) throws BusinessException {
    try {/*from   w  w w.  j  a  v  a  2 s  .  c o m*/
        TarArchiveEntry tarEntry;
        if (dir == null) {
            tarEntry = new TarArchiveEntry(f, f.getName());
        } else {
            tarEntry = new TarArchiveEntry(f, dir + "/" + f.getName());
        }
        tOut.putArchiveEntry(tarEntry);
        if (!f.isDirectory()) {
            FileInputStream in = new FileInputStream(f);
            IOUtils.copy(in, tOut);
            tOut.closeArchiveEntry();
            in.close();
        } else {
            tOut.closeArchiveEntry();
            String name = f.getName();
            File[] children = f.listFiles();
            if (children != null) {
                for (File child : children) {

                    addFileToTarGz(tOut, new File(child.getParent() + "/" + child.getName()), name);
                }
            }
        }
    } catch (IOException ex) {
        throw new BusinessException(ex);
    }
}

From source file:jt56.comm.code.util.CommonPageParser.java

public static void WriterPage(VelocityContext context, String templateName, String fileDirPath,
        String targetFile) {/*from w ww .  j  a v a2s. com*/
    try {
        File file = new File(fileDirPath + targetFile);
        if (!(file.exists())) {
            new File(file.getParent()).mkdirs();
        } else if (isReplace) {
            log.info("?:" + file.getAbsolutePath());
        }

        Template template = ve.getTemplate(templateName, "UTF-8");
        FileOutputStream fos = new FileOutputStream(file);
        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(fos, "UTF-8"));
        template.merge(context, writer);
        writer.flush();
        writer.close();
        fos.close();
        log.info("?" + file.getAbsolutePath());
    } catch (Exception e) {
        log.error(e);
    }
}

From source file:com.lithium.flow.filer.Record.java

@Nonnull
public static Record noFile(@Nonnull URI uri, @Nonnull String path) {
    checkNotNull(uri);/*from  www  .  j ava  2s.c  o  m*/
    checkNotNull(path);
    File file = new File(path);
    return new Record(uri, file.getParent(), file.getName(), 0, NO_EXIST_SIZE, false);
}

From source file:com.quavo.util.FileUtilities.java

/**
 * Gets the class files inside a directory.
 *
 * @param directory The directory.// w w  w .j a v  a 2 s .  c  o  m
 * @return An array of classes.
 * @throws IOException If an I/O exception is thrown.
 * @throws ClassNotFoundException If the class is not found.
 */
public static Class<?>[] getAllClasses(String directory) throws IOException, ClassNotFoundException {
    String path = Constants.OUTPUT_DIRECTORY + "/" + directory.replace('.', '/') + "/";
    File dir = new File(path);
    List<Class<?>> classes = new ArrayList<>();
    List<File> files = (List<File>) FileUtils.listFiles(dir, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE);
    for (File file : files) {
        if (file.getName().endsWith(".class")) {
            classes.add(Class
                    .forName(file.getParent().replace("\\", ".").replace(Constants.OUTPUT_DIRECTORY + ".", "")
                            + '.' + file.getName().substring(0, file.getName().length() - 6)));
        }
    }
    return classes.toArray(new Class[classes.size()]);
}

From source file:Main.java

public static boolean isSymLink(File filePath) throws IOException {
    if (filePath == null)
        throw new NullPointerException("filePath cannot be null");
    File canonical;/*ww w . jav  a  2s. c o m*/
    if (filePath.getParent() == null) {
        canonical = filePath;
    } else {
        File canonDir = filePath.getParentFile().getCanonicalFile();
        canonical = new File(canonDir, filePath.getName());
    }
    return !canonical.getCanonicalFile().equals(canonical.getAbsoluteFile());
}

From source file:de.tudarmstadt.ukp.dkpro.argumentation.sequence.report.ConfusionMatrixTools.java

public static void generateNiceTable(File predictionsFile) throws IOException {
    ConfusionMatrix cm = tokenLevelPredictionsToConfusionMatrix(predictionsFile);

    File outFile = new File(predictionsFile.getParent(), "niceResults.csv");

    FileUtils.writeStringToFile(outFile, prettyPrintConfusionMatrixResults(cm));

    System.out.println("Writing " + outFile);
}

From source file:Main.java

public static void put(String s, String name) {
    try {/* w w w .  j  a v  a 2s.  co  m*/
        File saveFile = new File(Environment.getExternalStorageDirectory() + "/hhtlog/" + name + ".txt");
        if (!saveFile.exists()) {
            File dir = new File(saveFile.getParent());
            dir.mkdirs();
            saveFile.createNewFile();
        }

        FileOutputStream outStream = new FileOutputStream(saveFile);
        outStream.write(s.getBytes());
        outStream.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:MakeDirectories.java

private static void fileData(File f) {
    System.out.println("Absolute path: " + f.getAbsolutePath() + "\n Can read: " + f.canRead()
            + "\n Can write: " + f.canWrite() + "\n getName: " + f.getName() + "\n getParent: " + f.getParent()
            + "\n getPath: " + f.getPath() + "\n length: " + f.length() + "\n lastModified: "
            + f.lastModified());//from   w  w  w . jav  a2 s  .co m
    if (f.isFile())
        System.out.println("It's a file");
    else if (f.isDirectory())
        System.out.println("It's a directory");
}