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

/**
 * Creates a temporary file with the specified prefix and extension.
 * /*from w  ww. ja v  a 2  s .c o  m*/
 * @param part
 *            the prefix for the file
 * @param ext
 *            the extension for the file
 * @param context
 *            the application's context
 * @return the created File
 * @throws Exception
 */
private static File createTemporaryFile(String part, String ext, Context context) throws Exception {
    File tempDir = Environment.getExternalStorageDirectory();
    tempDir = new File(tempDir.getAbsolutePath() + "/bv-temp/");
    if (!tempDir.exists()) {
        tempDir.mkdir();
    }
    return File.createTempFile(part, ext, tempDir);
}

From source file:com.ebay.logstorm.server.utils.LogStormServerDebug.java

private static File findAssemblyJarFile() {
    String projectRootDir = System.getProperty("user.dir");
    String assemblyModuleTargeDirPath = projectRootDir + "/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.ja v a  2 s  .  c  om*/
    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:Main.java

public static PackageInfo getAPKInfo(Context c, File apk) {
    if (!apk.exists())
        return null;
    String archiveFilePath = apk.getAbsolutePath();
    PackageManager pm = c.getPackageManager();
    //PackageManager.GET_ACTIVITIES = 1
    PackageInfo info = pm.getPackageArchiveInfo(archiveFilePath, 1);
    return info;//from   w w w  .ja v a  2  s. c o m
}

From source file:Main.java

private static void findJavaFiles(String projectDir, List<String> javaFilePaths) {
    File file = new File(projectDir);
    File[] files = file.listFiles();
    if (files == null || files.length == 0) {
        return;/*from   w  w  w. j av a 2s  . c  om*/
    }
    for (File f : files) {
        if (f.isDirectory()) {
            findJavaFiles(f.getAbsolutePath(), javaFilePaths);
        } else {
            if (f.getAbsolutePath().endsWith(".java")) {
                javaFilePaths.add(f.getAbsolutePath());
            }
        }
    }
}

From source file:Main.java

private static File getBackupFileName(File f, boolean isGoodBackup) {
    File f2 = null;// w  w  w.  j ava 2  s.co  m
    String prefix = f.getAbsolutePath() + (isGoodBackup ? ".good.bak." : ".corrupted.bak.");
    for (int i = MAX_BACKUP_FILES - 1; i > 2; i--) {
        File to = new File(prefix + i);
        File from = new File(prefix + (i - 1));
        if (to.exists())
            to.delete();
        if (from.exists()) {
            if (!from.renameTo(to))
                Log.e("cr3", "Cannot rename DB file " + from + " to " + to);
        }
    }
    f2 = new File(prefix + 2);
    if (f2.exists())
        if (!f2.delete())
            Log.e("cr3", "Cannot remove DB file " + f2);
    return f2;
}

From source file:Main.java

public static Bitmap getBitmap(String path) {
    if (path == null) {
        return null;
    }//from ww  w  .  java  2  s .  c o m
    File f = new File(path);
    if (f.exists()) {
        return BitmapFactory.decodeFile(f.getAbsolutePath());
    } else {
        return null;
    }

}

From source file:Main.java

public static void delete(File f) {
    if ((f != null) && (f.exists()) && (!(f.delete()))) {
        throw new RuntimeException(f.getAbsolutePath() + " doesn't be deleted!");
    }//from   w  ww  . ja va2 s.c  o m

}

From source file:AIR.Common.Utilities.Path.java

public static Collection<File> getFilesMatchingExtensions(String folder, final String[] extensions) {
    return (Collection<File>) FileUtils.listFiles(new File(folder), new IOFileFilter() {
        @Override/*w  w w .j av a  2 s . co m*/
        public boolean accept(File arg0) {
            return matches(arg0.getAbsolutePath());
        }

        @Override
        public boolean accept(File arg0, String arg1) {
            return matches(arg1);
        }

        private boolean matches(String file) {
            for (int counter1 = 0; counter1 < extensions.length; ++counter1) {
                if (StringUtils.endsWithIgnoreCase(file, extensions[counter1]))
                    return true;
            }
            return false;
        }

    }, TrueFileFilter.INSTANCE);
}

From source file:Main.java

private static String createDir(String path) {
    boolean isHaveSDCard = Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED);
    if (!isHaveSDCard) {
        return null;
    }//from   w  w w  .j a va2 s  .c  om
    File directory = Environment.getExternalStorageDirectory();
    File file = new File(directory.getAbsolutePath() + path);
    if (!file.exists()) {
        boolean isSuccess = file.mkdirs();
        if (isSuccess) {
            return file.getPath() + File.separator;
        } else {
            return null;
        }
    }
    return file.getPath() + File.separator;
}

From source file:FileUtils.java

static public String relativePath(File from, File to, char separatorChar) {
    String fromPath = from.getAbsolutePath();
    String toPath = to.getAbsolutePath();
    boolean isDirectory = from.isDirectory();
    return relativePath(fromPath, toPath, isDirectory, separatorChar);
}