Example usage for java.io File getAbsoluteFile

List of usage examples for java.io File getAbsoluteFile

Introduction

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

Prototype

public File getAbsoluteFile() 

Source Link

Document

Returns the absolute form of this abstract pathname.

Usage

From source file:com.twitter.heron.apiserver.utils.FileHelper.java

private static void addFileToArchive(TarArchiveOutputStream archiveOutputStream, File file, String base)
        throws IOException {
    final File absoluteFile = file.getAbsoluteFile();
    final String entryName = base + file.getName();
    final TarArchiveEntry tarArchiveEntry = new TarArchiveEntry(file, entryName);
    archiveOutputStream.putArchiveEntry(tarArchiveEntry);

    if (absoluteFile.isFile()) {
        Files.copy(file.toPath(), archiveOutputStream);
        archiveOutputStream.closeArchiveEntry();
    } else {// w w w . j  a  va  2  s.  c o  m
        archiveOutputStream.closeArchiveEntry();
        if (absoluteFile.listFiles() != null) {
            for (File f : absoluteFile.listFiles()) {
                addFileToArchive(archiveOutputStream, f, entryName + "/");
            }
        }
    }
}

From source file:Main.java

/**
 * Write to file in given folder// ww  w  .j  ava 2s  .c o m
 * @param fcontent
 * @return
 */
public static boolean writeFile(String fcontent, String path) {

    /*
     * Write file contents to file path
     */
    try {
        File file = new File(path);
        // If file does not exists, then create it
        if (!file.exists()) {
            file.createNewFile();
        }
        FileWriter fw = new FileWriter(file.getAbsoluteFile());
        BufferedWriter bw = new BufferedWriter(fw);
        bw.write(fcontent);
        bw.close();
        return true;
    } catch (Exception e) {
        return false;
    }
}

From source file:com.dfki.av.sudplan.Configuration.java

/**
 * Save the configuration file {@code config/sudplan3D.xml} from the
 * resources to the the file {@code file}. Adding the additional properties
 * {@code sudplan3D.user.dir} and {@code sudplan3D.working.dir}.
 *
 * @param file the configuration {@link File}
 * @param userHomeDir the user home directory
 * @param workingDir the working directory
 *///from w  w  w .jav a  2s .c o  m
private static void installConfigFile(File file, String userHomeDir, String workingDir) {
    log.debug("Installing configuration to {}...", file.getAbsoluteFile());
    try {
        ClassLoader loader = Configuration.class.getClassLoader();
        URL url = loader.getResource("config/sudplan3D.xml");
        XMLConfiguration xmlInitialConfig = new XMLConfiguration(url);
        xmlInitialConfig.addProperty("sudplan3D.user.dir", userHomeDir);
        xmlInitialConfig.addProperty("sudplan3D.working.dir", workingDir);
        xmlInitialConfig.save(file);
    } catch (ConfigurationException ex) {
        log.error(ex.toString());
    }
}

From source file:com.company.et.service.JsonService.java

/**
 *
 * @return JSON String// w w w  .jav a 2s. co m
 */
public static String readFromFile(File file) {

    String str = "";

    try (BufferedReader br = new BufferedReader(new FileReader(file.getAbsoluteFile()))) {

        String currentLine;

        while ((currentLine = br.readLine()) != null) {
            str += currentLine;
        }

        // @TODO: add LOG message
    } catch (IOException e) {
        e.printStackTrace();

        // @TODO: add LOG message
    }

    return str;
}

From source file:com.geewhiz.pacify.utils.FileUtils.java

public static void copyDirectory(File sourceDir, File targetDir) throws IOException {
    if (sourceDir.isDirectory()) {
        copyDirectoryRecursively(sourceDir.getAbsoluteFile(), targetDir.getAbsoluteFile());
    } else {//from w  w  w  .j a v  a  2s  . co m
        Files.copy(sourceDir.getAbsoluteFile().toPath(), targetDir.getAbsoluteFile().toPath(),
                java.nio.file.StandardCopyOption.COPY_ATTRIBUTES);
    }
}

From source file:com.apporiented.hermesftp.utils.IOUtils.java

/**
 * Tries to figure out the application's home directory.
 * /*w  w  w.ja  v  a 2  s  .  co  m*/
 * @return The directory.
 */
public static File getHomeDir() {
    File result = null;
    String cp = System.getProperty("java.class.path");
    StringTokenizer tokenizer = new StringTokenizer(cp, File.pathSeparator);
    if (tokenizer.countTokens() == 1) {
        File jar = new File(tokenizer.nextToken());
        try {
            result = jar.getCanonicalFile().getParentFile().getParentFile();
        } catch (IOException e) {
        }
    } else {
        File userDir = new File(System.getProperty("user.dir"));
        result = userDir.getAbsoluteFile().getParentFile();
    }
    return result;
}

From source file:com.oozierunner.core.FileManager.java

public static BufferedWriter getFileWriter(String fileName) throws IOException {

    System.out.println("File to write in :-> " + fileName);

    File file = new File(fileName);

    // if file doesnt exists, then create it
    if (!file.exists()) {
        file.createNewFile();/*from  w w w. ja va2s.c  o m*/
    }

    FileWriter fileWriter = new FileWriter(file.getAbsoluteFile());
    BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);

    return bufferedWriter;
}

From source file:gridool.db.partitioning.monetdb.MonetDBInvokeCopyIntoOperation.java

private static File prepareLoadFile(final String tableName) {
    DbCollection rootColl = DbCollection.getRootCollection();
    File colDir = rootColl.getDirectory();
    if (!colDir.exists()) {
        throw new IllegalStateException("Database directory not found: " + colDir.getAbsoluteFile());
    }//from   ww w.j a  v a2 s.co  m
    final File file = new File(colDir, tableName + ".csv");
    if (!file.exists()) {
        throw new IllegalStateException("Loading file not found: " + file.getAbsolutePath());
    }
    return file;
}

From source file:Main.java

public static boolean isSymboliclink(File file) throws IOException {
    File canon;
    if (file.getParent() == null) {
        canon = file;/*from   w ww.j  a  va  2  s. c o  m*/
    } else {
        File canonDir = file.getParentFile().getCanonicalFile();
        canon = new File(canonDir, file.getName());
    }
    return !canon.getCanonicalFile().equals(canon.getAbsoluteFile());
}

From source file:mitm.common.tools.PfxTool.java

private static KeyStore loadKeyStore(String keyFile, boolean shouldExist, String password) throws Exception {
    File file = new File(keyFile);

    file = file.getAbsoluteFile();

    KeyStore keyStore = KeyStore.getInstance("PKCS12");

    if (shouldExist && !file.exists()) {
        throw new FileNotFoundException(keyFile + " pfx file not found.");
    }//from  w  ww .  java  2 s  .c  o m

    /* initialize key store */
    char[] pw = password != null ? password.toCharArray() : null;

    if (file.exists()) {
        InputStream input = new FileInputStream(file);
        keyStore.load(input, pw);
        input.close();
    } else {
        // creates an empty keystore
        keyStore.load(null, pw);
    }

    return keyStore;
}