Example usage for java.io File getCanonicalPath

List of usage examples for java.io File getCanonicalPath

Introduction

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

Prototype

public String getCanonicalPath() throws IOException 

Source Link

Document

Returns the canonical pathname string of this abstract pathname.

Usage

From source file:com.ibm.soatf.tool.FileSystem.java

public static String getRelativePath(File file) {
    try {//from  ww  w.  java2  s . c  om
        final String filePath = file.getCanonicalPath();
        final String testPath = file.getParentFile().getParentFile().getParent();
        if (filePath.startsWith(testPath)) {
            return filePath.substring(testPath.length() + 1);
        } else {
            return null;
        }
    } catch (IOException e) {
        ;
    }
    return file.getAbsolutePath();
}

From source file:io.wcm.devops.conga.generator.util.FileUtil.java

/**
 * Get canoncial path of file/*from w ww  .j  a va 2  s. c o m*/
 * @param file File
 * @return Canonical path
 */
public static String getCanonicalPath(File file) {
    try {
        return file.getCanonicalPath();
    } catch (IOException ex) {
        return file.getAbsolutePath();
    }
}

From source file:com.enprowess.migration.bulkimport.impl.FileUtils.java

/**
 * returns the filename of the given file object
 * /*from  w  w w .  j a va2  s  . co  m*/
 * @param file
 * @return result
 */
public static String getFileName(final File file) {
    String result = null;

    if (file != null) {
        try {
            result = file.getCanonicalPath();
        } catch (IOException ioe) {
            result = file.toString();
            logger.info(ioe);
        }
    }

    return result;
}

From source file:edu.stanford.muse.Main.java

public static Archive getMessages(String alternateEmailAddrs, String baseDir, String files[]) throws Exception {
    MuseEmailFetcher m = new MuseEmailFetcher();
    List<String> selectedFoldersList = new ArrayList<String>();
    File dot = new File(".");
    String pwd = dot.getCanonicalPath();
    String sessionName = null;/*from   w w w  .  j  a  v  a2 s .  co m*/

    if (files.length == 0) {
        log.error("No inputs specified?!");
        return null;
    }

    for (String f : files) {
        String dir = Util.dirName(f);
        if (dir == null)
            dir = pwd;
        String file = Util.baseName(f);
        m.addMboxAccount("mbox", dir, false);
        selectedFoldersList.add(dir + "^-^" + f);
        if (sessionName == null)
            sessionName = file; // assign first file as the session name
    }

    Archive archive = Archive.createArchive();
    archive.setup(baseDir, null, new String[0] /* default indexoptions */);
    // need to set up its blobs etc

    String[] selectedFolders = selectedFoldersList.toArray(new String[selectedFoldersList.size()]);
    FetchConfig fc = new FetchConfig();
    fc.downloadMessages = fc.downloadAttachments = true;
    m.fetchAndIndexEmails(archive, selectedFolders, false, fc, null);
    return archive; // TODO: need to return proper result
}

From source file:Main.java

/**
 * Returns the path of one File relative to another.
 * <p/>//w w w .ja  va  2s  .  c  o  m
 * From http://stackoverflow.com/questions/204784
 *
 * @param target the target directory
 * @param base   the base directory
 * @return target's path relative to the base directory
 */
public static String getRelativePath(File target, File base) {
    String[] baseComponents;
    String[] targetComponents;
    try {
        baseComponents = base.getCanonicalPath().split(Pattern.quote(File.separator));
        targetComponents = target.getCanonicalPath().split(Pattern.quote(File.separator));
    } catch (IOException e) {
        return target.getAbsolutePath();
    }

    // skip common components
    int index = 0;
    for (; index < targetComponents.length && index < baseComponents.length; ++index) {
        if (!targetComponents[index].equals(baseComponents[index]))
            break;
    }

    StringBuilder result = new StringBuilder();
    if (index != baseComponents.length) {
        // backtrack to base directory
        for (int i = index; i < baseComponents.length; ++i)
            result.append("..").append(File.separator);
    }
    for (; index < targetComponents.length; ++index)
        result.append(targetComponents[index]).append(File.separator);
    if (!target.getPath().endsWith("/") && !target.getPath().endsWith("\\")) {
        // remove final path separator
        result.delete(result.length() - "/".length(), result.length());
    }
    return result.toString();
}

From source file:Main.java

public static void getScripts(File project, Vector<String> scripts, String projectPath) throws IOException {
    if (project != null && project.isFile()) {
        String canonicalPath = project.getCanonicalPath();
        //System.out.println("bbbbbbbbbbb:" + canonicalPath + "  " + projectPath);
        int index = canonicalPath.indexOf(projectPath);//lastIndexOf(System.getProperty("file.separator") + "workspace" + System.getProperty("file.separator"));
        String relativePath = canonicalPath.substring(projectPath.length(), canonicalPath.length());
        //System.out.println("bbbbbbbbbbb:" + relativePath);
        //scripts.add(project.getCanonicalPath());
        scripts.add(relativePath);/*w ww. j av  a 2 s  .c  om*/
    } else if (project != null && project.isDirectory()) {
        File[] files = project.listFiles();
        for (int i = 0; i < files.length; i++) {
            getScripts(files[i], scripts, projectPath);
        }
    }
}

From source file:musicmetadatak1009705.Main.java

public static void aVAJAVAFileMp3Scan(File dir) {
    try {//ww  w  . j  a  v a 2 s  . c  om
        String[] extensions = new String[] { "mp3" };
        System.out.println(
                "Getting all .mp3 files in " + dir.getCanonicalPath() + " including those in subdirectories");
        List<File> files = (List<File>) FileUtils.listFiles(dir, extensions, true);
        for (File file : files) {
            System.out.println("file: " + file.getCanonicalPath());
        }
    } catch (IOException ex) {
    }
}

From source file:azkaban.soloserver.AzkabanSingleServerTest.java

private static String getSqlScriptsDir() throws IOException {
    // Dummy because any resource file works.
    Path resources = Paths.get(getConfPath()).getParent();
    Path azkabanRoot = resources.getParent().getParent().getParent().getParent();

    File sqlScriptDir = Paths.get(azkabanRoot.toString(), AZKABAN_DB_SQL_PATH).toFile();
    return sqlScriptDir.getCanonicalPath();
}

From source file:com.l2jfree.gameserver.util.GPLLicenseChecker.java

private static void parse(File f) throws IOException {
    System.out.println(f.getCanonicalPath());

    if (f.isDirectory()) {
        for (File tmp : f.listFiles(FILTER))
            parse(tmp);/*from w  ww  .  j ava2  s  . c o  m*/
    } else {
        List<String> tmpList = read(f);

        if (tmpList == null)
            return;

        ArrayList<String> list2 = new ArrayList<String>();

        for (String line : LICENSE)
            list2.add(line);

        boolean foundPackageDeclaration = false;
        for (String line : tmpList)
            if (foundPackageDeclaration |= containsPackageName(line))
                list2.add(line);

        PrintStream ps = null;
        try {
            ps = new PrintStream(f);

            for (String line : list2)
                ps.println(line);
        } finally {
            IOUtils.closeQuietly(ps);
        }
    }
}

From source file:azkaban.webapp.AzkabanWebServerTest.java

private static String getSqlScriptsDir() throws IOException {
    // Dummy because any resource file works.
    final String dummyResourcePath = getUserManagerXmlFile();
    Path resources = Paths.get(dummyResourcePath).getParent();
    Path azkabanRoot = resources.getParent().getParent().getParent().getParent();

    File sqlScriptDir = Paths.get(azkabanRoot.toString(), AZKABAN_DB_SQL_PATH).toFile();
    return sqlScriptDir.getCanonicalPath();
}