Example usage for java.io File getAbsolutePath

List of usage examples for java.io File getAbsolutePath

Introduction

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

Prototype

public String getAbsolutePath() 

Source Link

Document

Returns the absolute pathname string of this abstract pathname.

Usage

From source file:fr.logfiletoes.Main.java

/**
 * Get config file and check if existe//from  w  w  w.  j  a  v  a  2s  . c om
 * @return 
 */
public static String getConfigFilePath() {
    String configFile = System.getProperty("fr.logfiletoes.config.file");
    if (configFile == null) {
        LOG.severe("-Dfr.logfiletoes.config.file is required for config file");
        System.exit(1);
    } else {
        File config = new File(configFile);
        if (!config.exists()) {
            LOG.severe("\"" + config.getAbsolutePath() + "\" not found");
            System.exit(2);
        }
        if (!config.isFile()) {
            LOG.severe("\"" + config.getAbsolutePath() + "\" is not file");
            System.exit(3);
        }
    }
    return configFile;
}

From source file:Main.java

private static void deleteDirectoryContent(String directoryPath) {
    File dir = new File(directoryPath);
    if (dir.exists() && dir.isDirectory()) {
        String[] children = dir.list();
        for (int i = 0; i < children.length; i++) {
            File file = new File(dir, children[i]);
            if (file.isDirectory()) {
                deleteDirectoryContent(file.getAbsolutePath());
            } else {
                file.delete();//from w w w .  j  a v  a 2s .  c om
            }
        }
        dir.delete();
    }
}

From source file:de.tudarmstadt.ukp.dkpro.spelling.experiments.data.util.DataUtil.java

public static Map<String, String> getAllDatasets(String path, String[] extensions) throws IOException {

    Map<String, String> datasetMap = new HashMap<String, String>();

    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    for (Resource resource : resolver.getResources(path)) {
        for (File datasetFile : FileUtils.listFiles(resource.getFile(), extensions, true)) {
            datasetMap.put(datasetFile.getAbsolutePath(), datasetFile.getParentFile().getName());
        }//  w w w . ja v a  2s .  co m
    }

    return datasetMap;
}

From source file:com.ebay.logstorm.core.utils.PipelineEnvironmentLoaderForTest.java

private static File findAssemblyJarFile(String relativeToHomePath) {
    String projectRootDir = System.getProperty("user.dir");
    String assemblyModuleTargeDirPath = relativeToHomePath == null ? projectRootDir + "/assembly/target/"
            : projectRootDir + relativeToHomePath + "/assembly/target/";
    File assemblyTargeDirFile = new File(assemblyModuleTargeDirPath);
    if (!assemblyTargeDirFile.exists()) {
        throw new IllegalStateException(
                assemblyModuleTargeDirPath + " not found, please execute 'mvn install -DskipTests' under "
                        + projectRootDir + " to build the project firstly and retry");
    }//ww w  .j  a va 2  s .  co  m
    String jarFileNameWildCard = "logstorm-assembly-*.jar";
    Collection<File> jarFiles = FileUtils.listFiles(assemblyTargeDirFile,
            new WildcardFileFilter(jarFileNameWildCard), TrueFileFilter.INSTANCE);
    if (jarFiles.size() == 0) {
        throw new IllegalStateException(
                "jar is not found, please execute 'mvn install -DskipTests' from project root firstly and retry");
    }
    File jarFile = jarFiles.iterator().next();
    LOG.debug("Found pipeline.jar: {}", jarFile.getAbsolutePath());
    return jarFile;
}

From source file:com.mirth.connect.cli.launcher.CommandLineLauncher.java

private static void addSharedLibsToClasspath(List<URL> urls) throws Exception {
    IOFileFilter sharedLibFileFilter = new WildcardFileFilter("*-shared.jar");
    File extensions = new File("./extensions");

    if (extensions.exists() && extensions.isDirectory()) {
        Collection<File> sharedLibs = FileUtils.listFiles(extensions, sharedLibFileFilter,
                FileFilterUtils.trueFileFilter());

        for (File sharedLib : sharedLibs) {
            logger.trace("adding library to classpath: " + sharedLib.getAbsolutePath());
            urls.add(sharedLib.toURI().toURL());
        }//ww w .  j  a v a2 s.  co m
    } else {
        logger.warn("no extensions found");
    }
}

From source file:jp.furplag.util.commons.FileUtils.java

private static boolean createNewFile(String filename, boolean printStackTrace) {
    try {/*from  w  w  w.  j a va 2s  . c  om*/
        if (StringUtils.isSimilarToBlank(filename))
            throw new IOException("path must not be empty.");
        String path = normalize(filename);
        File file = new File(path);
        if (file.exists() && file.isDirectory())
            throw new IOException(normalize(file.getAbsolutePath()) + " is directory.");
        path = normalize(file.getAbsolutePath());
        forceMkdir(StringUtils.truncateLast(path, "/.*"));
        if (!file.exists())
            return file.createNewFile();

    } catch (Exception e) {
        if (printStackTrace)
            e.printStackTrace();
    }

    return false;
}

From source file:Main.java

public static void delete(File file) {
    if (!file.delete()) {
        throw new RuntimeException("File " + file.getAbsolutePath() + " can't be deleted.");
    }/*from www  .j av  a2 s . c  o  m*/
}

From source file:es.amplia.research.maven.protodocbook.tools.FileHelper.java

public static boolean copyDir(File _in, File _out) {
    try {//w ww  .  ja v  a 2 s .c  o  m
        log.info("Copying " + _in.getName() + " to " + _out.getAbsolutePath());
        FileUtils.copyDirectory(_in, _out);
        return true;
    } catch (IOException e) {
        log.error("File copy error", e);
        return false;
    }
}

From source file:Main.java

public static void traverseFolder(Map<String, File> fileMap, File rootFolder, File folderInCheck) {
    if (folderInCheck.isFile()) {
        int length = (int) rootFolder.getAbsolutePath().length();
        String pathKey = folderInCheck.getAbsolutePath().substring(length);
        fileMap.put(pathKey, folderInCheck);
        return;//from   www.  ja va2s.  co  m
    }

    String[] names = folderInCheck.list(new FilenameFilter() {
        // for filtering some files, such as ".xml"
        public boolean accept(File dir, String name) {
            return true;
        }
    });

    if (names == null || names.length == 0) {
        return;
    }

    File[] files = folderInCheck.listFiles();
    if (files == null || files.length == 0) {
        return;
    }

    for (File child : files) {
        traverseFolder(fileMap, rootFolder, child);
    }
}

From source file:Main.java

public static void compressAFileToZip(File zip, File source) throws IOException {
    Log.d("source: " + source.getAbsolutePath(), ", length: " + source.length());
    Log.d("zip:", zip.getAbsolutePath());
    zip.getParentFile().mkdirs();// ww  w.  ja  v a  2  s  .co  m
    File tempFile = new File(zip.getAbsolutePath() + ".tmp");
    FileOutputStream fos = new FileOutputStream(tempFile);
    BufferedOutputStream bos = new BufferedOutputStream(fos);
    ZipOutputStream zos = new ZipOutputStream(bos);
    ZipEntry zipEntry = new ZipEntry(source.getName());
    zipEntry.setTime(source.lastModified());
    zos.putNextEntry(zipEntry);

    FileInputStream fis = new FileInputStream(source);
    BufferedInputStream bis = new BufferedInputStream(fis);
    byte[] bArr = new byte[4096];
    int byteRead = 0;
    while ((byteRead = bis.read(bArr)) != -1) {
        zos.write(bArr, 0, byteRead);
    }
    zos.flush();
    zos.closeEntry();
    zos.close();
    Log.d("zipEntry: " + zipEntry, "compressedSize: " + zipEntry.getCompressedSize());
    bos.flush();
    fos.flush();
    bos.close();
    fos.close();
    bis.close();
    fis.close();
    zip.delete();
    tempFile.renameTo(zip);
}