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:JarMaker.java

/**
 * Unpack the jar file to a directory, till teaf files
 * @param file/*  w w  w  .j  av  a  2s.c  o m*/
 * @param file1
 * @throws IOException
 */
public static void unpackAppJar(File file, File file1) throws IOException {

    unpackAppJar(file.getCanonicalPath(), file1.getCanonicalPath());
}

From source file:com.nokia.dempsy.mpcluster.zookeeper.ZookeeperTestServer.java

private static File genZookeeperDataDir() {
    File zkDir = null;
    try {//ww  w.  j av  a  2s .  com
        zkDir = File.createTempFile("zoo", "data");
        if (!zkDir.delete())
            throw new IOException("Can't rm zkDir " + zkDir.getCanonicalPath());
        if (!zkDir.mkdir())
            throw new IOException("Can't mkdir zkDir " + zkDir.getCanonicalPath());
    } catch (IOException e) {
        fail("Can't make zookeeper data dir");
    }
    return zkDir;
}

From source file:com.excelsiorjet.api.util.Utils.java

public static String getCanonicalPath(File path) {
    try {/*from  w ww  .ja v a2  s  .  co m*/
        return path.getCanonicalPath();
    } catch (IOException e) {
        // getCanonicalPath throws IOException,
        // so just return absolute path in a very rare case of IOException as there is no other
        // appropriate way to handle this situation.
        return path.getAbsolutePath();
    }
}

From source file:JarMaker.java

/**
 * @param f_name : source zip file/*from  www  .j av a  2  s.c o m*/
 * @param dir_name : target dir file
 */
public static void unpackJar(File f_name, File dir_name) throws IOException {

    unpackJar(f_name.getCanonicalPath(), dir_name.getCanonicalPath());
}

From source file:com.limegroup.gnutella.util.Launcher.java

/**
 * Launches the Finder and selects the given File
 *///w  w  w .ja va  2 s .  co m
private static String[] selectFileCommand(File file) {
    String path = null;
    try {
        path = file.getCanonicalPath();
    } catch (IOException err) {
        path = file.getAbsolutePath();
    }

    String[] command = new String[] { "osascript", "-e", "set unixPath to \"" + path + "\"", "-e",
            "set hfsPath to POSIX file unixPath", "-e", "tell application \"Finder\"", "-e", "activate", "-e",
            "select hfsPath", "-e", "end tell" };

    return command;
}

From source file:elaborate.editor.config.Configuration.java

private static Reader createConfigReader() {
    try {//w w  w.ja  v a2 s  .  c o m
        File file = new File(CONFIG_XML);
        System.out.println(CLASS_NAME + " - Loading configuration from " + file.getCanonicalPath());
        if (!file.isFile()) {
            // try resourceAsStream
            InputStream resourceAsStream = Thread.currentThread().getContextClassLoader()
                    .getResourceAsStream("config.xml");
            if (resourceAsStream == null) {
                fatalError("Cannot access configuration file '" + file.getCanonicalPath() + "'");
            }
            return new InputStreamReader(resourceAsStream);
        }
        String content = FileUtils.readFileToString(file, "UTF-8");
        return new StringReader(content);
    } catch (IOException e) {
        throw new RuntimeException("Failed to load configuration", e);
    }
}

From source file:com.thoughtworks.go.util.FileUtil.java

public static String getCanonicalPath(File workDir) {
    try {/*ww  w .  ja  v  a  2  s.  c  o  m*/
        return workDir.getCanonicalPath();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:jeplus.util.RelativeDirUtil.java

/**
 * Check the path is absolute or not. If it is not, use the specified BaseDir and calculate absolute path
 *
 * @param thispath The Path to check/*w  ww .  j  a v a 2  s  .c  om*/
 * @param BaseDir The Base Directory to which a relative path is associated
 * @return The absolute (canonical where possible) path
 */
public static String checkAbsolutePath(String thispath, String BaseDir) {
    String abspath;
    File path = new File(thispath);
    if (!path.isAbsolute()) {
        path = new File(BaseDir + thispath);
    }
    try {
        abspath = path.getCanonicalPath();
    } catch (IOException ex) {
        Logger.getLogger(RelativeDirUtil.class.getName()).log(Level.WARNING, null, ex);
        abspath = path.getAbsolutePath();
    }
    return abspath;
}

From source file:com.github.drochetti.javassist.maven.ClassnameExtractor.java

/**
 * Remove passed parent directory from passed file name and replace
 * directory separator with dots.//from ww  w .j av  a 2 s .co m
 * <p>
 * e.g.:
 * </p>
 * <ul>
 * <li>parantDirectory: <code>/tmp/my/parant/src/</code></li>
 * <li>classFile: <code>/tmp/my/parent/src/foo/bar/MyApp.class</li>
 * </ul>
 * returns: <code>foo.bar.MyApp</code>
 * 
 * @param parentDirectory
 * @param classFile
 * @return class name extracted from file name or <code>null</code>
 * @throws IOException
 */
public static String extractClassNameFromFile(final File parentDirectory, final File classFile)
        throws IOException {
    if (null == classFile) {
        return null;
    }
    final String qualifiedFileName = parentDirectory != null
            ? classFile.getCanonicalPath().substring(parentDirectory.getCanonicalPath().length() + 1)
            : classFile.getCanonicalPath();
    return removeExtension(qualifiedFileName.replace(File.separator, "."));
}

From source file:com.tacitknowledge.util.discovery.ClasspathUtils.java

public static String getCanonicalPath(String path) {
    File file = new File(path);
    String canonicalPath = null;//from www  .j a v  a2 s.  com
    if (file.exists()) {
        try {
            canonicalPath = file.getCanonicalPath();
        } catch (IOException e) {
            log.warn("Error resolving filename to canonical file: " + e.toString());
        }
    }

    if (canonicalPath == null) {
        canonicalPath = file.getPath();
    }

    return canonicalPath;
}