Example usage for java.io File getPath

List of usage examples for java.io File getPath

Introduction

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

Prototype

public String getPath() 

Source Link

Document

Converts this abstract pathname into a pathname string.

Usage

From source file:de.bund.bfr.fskml.ScriptFactory.java

/**
 * /*from w  ww  . j  a  va2s  .  co  m*/
 * @param file A file containing script code (e.g.: R code)
 * @return instance of Script
 * @throws IOException
 */
public static Script createScript(final File file) throws IOException {
    Script script = null;

    String language = FilenameUtils.getExtension(file.getPath());
    if (language.toLowerCase().startsWith("r")) {
        script = new RScript(file);
    }
    if (language.toLowerCase().startsWith("py")) {
        script = new PythonScript(file);
    }

    return script;
}

From source file:gov.nih.nci.cabig.caaers.testdata.TestDataFileUtils.java

/**
 * Returns a file object representation of the fileName
 * @param folder// w ww .j  a va 2 s.c om
 * @param fileName
 * @return
 */
public static File getFileObject(File folder, String fileName) {
    return new File(folder.getPath() + "/" + fileName);
}

From source file:Main.java

/**
 * @param context//from w ww.j a  v  a2 s  .c  o m
 * @param dirName Only the folder name, not full path.
 * @return app_cache_path/dirName
 */
public static String getDiskCacheDir(Context context, String dirName) {
    String cachePath = null;
    if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
        File externalCacheDir = context.getExternalCacheDir();
        if (externalCacheDir != null) {
            cachePath = externalCacheDir.getPath();
        }
    }
    if (cachePath == null) {
        File cacheDir = context.getCacheDir();
        if (cacheDir != null && cacheDir.exists()) {
            cachePath = cacheDir.getPath();
        }
    }

    return cachePath + File.separator + dirName;
}

From source file:Main.java

@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
public static long getSDFreeSize() {
    File path = Environment.getExternalStorageDirectory();
    if (path != null && path.exists() && path.isDirectory()) {
        StatFs sf = new StatFs(path.getPath());
        long blockSize = sf.getBlockSizeLong();
        long freeBlocks = sf.getAvailableBlocksLong();
        return (freeBlocks * blockSize) / 1024 / 1024;
    }/*from   w  w  w  . j  av a2 s  .c  o  m*/
    return -1;
}

From source file:com.microsoft.alm.common.utils.ArgumentHelper.java

public static void checkIfFileWriteable(final File file) {
    if (!file.canWrite()) {
        throw new IllegalArgumentException(String.format(NOT_WRITEABLE_FILE_MSG, file.getPath()));
    }/*ww  w  . ja v a2s .  c  o  m*/
}

From source file:de.ks.option.properties.PropertiesOptionSource.java

protected static String getPropertiesFile() {
    String workingDir = System.getProperty("user.dir");
    if (workingDir.endsWith("bin")) {
        File parentFile = new File(workingDir).getParentFile();
        return parentFile.getPath() + File.separator + "options." + PROPERTIES_FILENAME;
    } else {/*from www . ja  va 2 s  .  c  om*/
        return workingDir + File.separator + "options." + PROPERTIES_FILENAME;
    }
}

From source file:ZipHelper.java

private static void fileToZip(File file, ZipOutputStream zout, File baseDir) throws Exception {
    String entryName = file.getPath().substring(baseDir.getPath().length() + 1);
    if (File.separatorChar != '/')
        entryName = entryName.replace(File.separator, "/");
    if (file.isDirectory()) {
        zout.putNextEntry(new ZipEntry(entryName + "/"));
        zout.closeEntry();/*from   www.ja  v  a  2 s . c  om*/
        File[] files = file.listFiles();
        for (int i = 0; i < files.length; i++)
            fileToZip(files[i], zout, baseDir);
    } else {
        FileInputStream is = null;
        try {
            is = new FileInputStream(file);
            zout.putNextEntry(new ZipEntry(entryName));
            streamCopy(is, zout);
        } finally {
            zout.closeEntry();
            if (is != null)
                is.close();
        }
    }
}

From source file:Main.java

private static boolean copyFile(File assetFile, File storageFile, AssetManager assetManager) {
    try {/*from w w  w  .j a  va  2 s  . com*/
        InputStream in = assetManager.open(assetFile.getPath());
        FileOutputStream out = new FileOutputStream(storageFile);
        byte[] buffer = new byte[1024];
        int read;
        while ((read = in.read(buffer)) != -1) {
            out.write(buffer, 0, read);
        }
        in.close();
        out.close();
        return true;
    } catch (FileNotFoundException e) {
        return false;
    } catch (IOException e) {
        return false;
    }
}

From source file:fedora.utilities.Log4J.java

/**
 * Initializes Log4J from an XML file.//from ww  w . j  ava 2 s  .  c  om
 * 
 * @param xmlFile the Log4J xml file.
 * @throws IOException if configuration fails due to problems with the file.
 */
public static void initFromXMLFile(File xmlFile) throws IOException {
    if (!xmlFile.exists()) {
        throw new FileNotFoundException(xmlFile.getPath());
    }
    DOMConfigurator.configure(xmlFile.getPath());
}

From source file:Main.java

public static boolean copyAssetsToInternalStorage(File assetFile, File storageFile, AssetManager assetManager) {
    try {/*from  w ww  . ja  v  a 2s.c  o m*/
        String[] assets = assetManager.list(assetFile.getPath());
        if (assets.length == 0) {
            //                return copyFile(assetManager.openFd(assetFile.getPath()).getFileDescriptor(), storageFile); //Fail!!!
            return copyFile(assetFile, storageFile, assetManager);
        } else {
            storageFile.mkdir();
            for (String file : assets) {
                copyAssetsToInternalStorage(new File(assetFile, file), new File(storageFile, file),
                        assetManager);
            }
        }
        return true;
    } catch (IOException ex) {
        return false;
    }
}