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

/**
 * Determine the main folder of the external SD card containing the given file.
 *
 * @param file the file.//from   w  w  w. j  a  va2 s  . c o m
 * @return The main folder of the external SD card containing this file, if the file is on an SD card. Otherwise,
 * null is returned.
 */
@TargetApi(Build.VERSION_CODES.KITKAT)
public static String getExtSdCardFolder(@NonNull final File file) {
    String[] extSdPaths = getExtSdCardPaths();
    try {
        for (String extSdPath : extSdPaths) {
            if (file.getCanonicalPath().startsWith(extSdPath)) {
                return extSdPath;
            }
        }
    } catch (IOException e) {
        return null;
    }
    return null;
}

From source file:com.alibaba.jstorm.utils.PathUtils.java

public static String getCanonicalPath(String fileName) {
    String ret = null;/*from  w  w  w  .  j  a v a 2  s. c  o  m*/
    File file = new File(fileName);
    if (file.exists()) {
        try {
            ret = file.getCanonicalPath();
        } catch (IOException e) {
            LOG.error("", e);
        }
    } else {
        LOG.warn(fileName + " doesn't exist ");
    }

    return ret;
}

From source file:com.robin.testcase.ApkResigner.java

private static String getReSignedAutName(final File autFile) {
    String autName = autFile.getName();
    String autFileCanonical = null;
    try {//from  ww w  .  j a va  2 s  .  c o m
        autFileCanonical = autFile.getCanonicalPath();
    } catch (IOException e) {
        e.printStackTrace();
    }

    String newAutNameFolderPart = getUnderLinedPath(autFileCanonical);
    String newAutNameFileNamePart = FilenameUtils.getBaseName(autName);
    String newAutName = newAutNameFolderPart + "_" + newAutNameFileNamePart;
    String newAutNameWithExtension = newAutName + "_" + getAutVersion(autFile) + "."
            + FilenameUtils.getExtension(autName);
    return newAutNameWithExtension;
}

From source file:Main.java

public static void printFilePath(String pathname) {
    File f = new File(pathname);
    System.out.println("File  Name: " + f.getName());
    System.out.println("File  exists: " + f.exists());
    System.out.println("Absolute Path: " + f.getAbsolutePath());

    try {/*w  w  w . j  ava2s.  c  om*/
        System.out.println("Canonical Path: " + f.getCanonicalPath());
    }

    catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:org.cloudfoundry.client.lib.SampleProjects.java

/**
 *
 * @return The directory containing a simple standalone Ruby script
 * @throws IOException/*  w  w w.  j  ava2  s.  c  om*/
 */
public static File standaloneRuby() throws IOException {
    File file = new File(TEST_APP_DIR + "/standalone-ruby-app");
    assertTrue("Expected test app at " + file.getCanonicalPath(), file.exists());
    return file;
}

From source file:org.cloudfoundry.client.lib.SampleProjects.java

/**
 *
 * @return The directory containign a simple standalone Node app
 * @throws IOException/*from   ww w. ja va2 s  .  c o  m*/
 */
public static File standaloneNode() throws IOException {
    File file = new File(TEST_APP_DIR + "/standalone-node-app");
    assertTrue("Expected test app at " + file.getCanonicalPath(), file.exists());
    return file;
}

From source file:FileUtils.java

/**
 * Returns all jpg images from a directory in an array.
 *
 * @param directory                 the directory to start with
 * @param descendIntoSubDirectories should we include sub directories?
 * @return an ArrayList<String> containing all the files or nul if none are found..
 * @throws IOException/* w  w w  .  j av  a  2 s . co  m*/
 */
public static ArrayList<String> getAllImages(File directory, boolean descendIntoSubDirectories)
        throws IOException {
    ArrayList<String> resultList = new ArrayList<String>(256);
    File[] f = directory.listFiles();
    for (File file : f) {
        if (file != null && file.getName().toLowerCase().endsWith(".jpg")
                && !file.getName().startsWith("tn_")) {
            resultList.add(file.getCanonicalPath());
        }
        if (descendIntoSubDirectories && file.isDirectory()) {
            ArrayList<String> tmp = getAllImages(file, true);
            if (tmp != null) {
                resultList.addAll(tmp);
            }
        }
    }
    if (resultList.size() > 0)
        return resultList;
    else
        return null;
}

From source file:com.huawei.streaming.cql.CQLTestCommons.java

/**
 * ?sql??/*from   w w  w  .  j  a  va 2 s  .c  om*/
 *
 * @param qf 
 * @return ??sql
 * @throws Exception ?
 */
public static List<String> addFile(File qf) throws Exception {
    CQLFileReader reader = new CQLFileReader();
    reader.readCQLs(qf.getCanonicalPath());
    return reader.getResult();
}

From source file:com.sap.prd.mobile.ios.mios.ScriptRunner.java

private static int execute(PrintStream out, File scriptFile, String... args) throws IOException {
    String[] _args = new String[args.length + 1];
    System.arraycopy(args, 0, _args, 1, args.length);
    _args[0] = scriptFile.getCanonicalPath();

    return Forker.forkProcess(out, null, _args);
}

From source file:com.l2jfree.tools.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  ww  w.  j a va  2s. c o  m
    } else {
        final List<String> tmpList = read(f);

        // to skip the com.sun.script classes
        if (tmpList == null)
            return;

        // GPL license check
        final L2TextBuilder tb = new L2TextBuilder();

        if (!CLEARED)
            for (String line : CONFIDENTIAL)
                tb.appendNewline(line);

        for (String line : LICENSE)
            tb.appendNewline(line);

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

        // non-Javadoc check
        final String content = tb.moveToString();

        String regex1 = "";
        regex1 += "[ \t]+/\\* \\(non-Javadoc\\)\\r\\n";
        regex1 += "[ \t]+\\* @see [^#]+#[^\\(]+\\([^\\)]*\\)\\r\\n";
        regex1 += "[ \t]+\\*/\\r\\n";

        String regex2 = "";
        regex2 += "[ \t]+/\\*\\r\\n";
        regex2 += "[ \t]+\\* \\(non-Javadoc\\)\\r\\n";
        regex2 += "[ \t]+\\* @see [^#]+#[^\\(]+\\([^\\)]*\\)\\r\\n";
        regex2 += "[ \t]+\\*/\\r\\n";

        final String content2 = content.replaceAll(regex1, "").replaceAll(regex2, "");

        if (!content.equals(content2))
            MODIFIED.add(f.getPath() + ": (non-Javadoc)");

        FileUtils.writeStringToFile(f, content2);
    }
}