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:com.microsoft.alm.common.utils.ArgumentHelper.java

public static void checkIfFile(final File file) {
    checkNotNull(file, "file");
    if (file.isDirectory()) {
        throw new IllegalArgumentException(String.format(NOT_FILE_MSG, file.getPath()));
    }//  www.  ja  v  a 2s. c o  m
}

From source file:Main.java

public static void CopyResFile(InputStream resStream, String sTarget) {
    File tmpFile = WriteStreamToFile(resStream);
    if (tmpFile != null) {
        RunSystemCmd(String.format("busybox cp %s %s; chmod 777 %s", tmpFile.getPath(), sTarget, sTarget));
        tmpFile.delete();/*from   www  .  j av  a2 s.co m*/
    }
}

From source file:Main.java

public static File getDiskAppCacheDir(Context context, String uniqueName) {
    // Check if media is mounted or storage is built-in, if so, try and use
    // external cache dir
    // otherwise use internal cache dir
    final File externalCache = getExternalCacheDir(context);
    final String cachePath = (externalCache == null) ? context.getCacheDir().getPath()
            : externalCache.getPath();

    return new File(cachePath + File.separator + uniqueName);
}

From source file:com.xebialabs.deployit.cli.ext.mustachify.io.Files2.java

/**
 * Returns the path to an (almost certainly) non-existent file in the default temporary 
 * directory. The file itself is <em>not</em> created.
 * //www.  j a v a 2  s.  c  o  m
 * Due to the small possibility that another process claims the name before it can
 * be used, callers may wish to check for existence using {@link File#exists()} to
 * be sure.
 */
public static String getTempFilePath(String basename, String ext) throws IOException {
    File tempFile = File.createTempFile(basename, ext);
    String tempFilePath = tempFile.getPath();
    tempFile.delete();
    return tempFilePath;
}

From source file:Main.java

public static String getSDPath() {
    String result = "";
    File sdDir = null;
    if (isSdCardExist()) {
        sdDir = Environment.getExternalStorageDirectory();
    }//from   w ww .  j ava 2  s .c  om

    if (sdDir != null) {
        result = sdDir.getPath();
    }
    return result;
}

From source file:Main.java

public static int[] getSize(File bitmapFile) {
    int[] hw = new int[] { 0, 0 };
    BitmapFactory.Options opts = new BitmapFactory.Options();
    opts.inJustDecodeBounds = true;//w  w w  .  j  ava  2s .  c o  m
    BitmapFactory.decodeFile(bitmapFile.getPath(), opts);
    hw[0] = opts.outWidth;
    hw[1] = opts.outHeight;
    return hw;
}

From source file:com.aionemu.packetsamurai.parser.valuereader.ClientStringReader.java

public static void load() {
    //PacketSamurai.getUserInterface().log("Loading Client strings... Please wait.");
    Util.drawTitle("Client Strings");
    File stringsFolder = new File("./data/client_strings");
    if (!stringsFolder.exists()) {
        stringsFolder.mkdir();// w w w . ja v a2  s  .  co m
    }
    try {
        File[] files = stringsFolder.listFiles();
        File[] arrayOfFile1;
        int j = (arrayOfFile1 = files).length;
        for (int i = 0; i < j; i++) {
            File sFile = arrayOfFile1[i];
            File xml = new File(sFile.getPath());

            String stringFile = FileUtils.readFileToString(xml);
            String[] strings = StringUtils.substringsBetween(stringFile, "<string>", "</string>");
            if (strings != null) {
                String[] arrayOfString1;
                int m = (arrayOfString1 = strings).length;
                for (int k = 0; k < m; k++) {
                    String string = arrayOfString1[k];
                    int stringId = Integer.parseInt(StringUtils.substringBetween(string, "<id>", "</id>"));
                    String stringBody = StringUtils.substringBetween(string, "<body>", "</body>");
                    stringsById.put(Integer.valueOf(stringId), stringBody);
                }
            }
        }
        PacketSamurai.getUserInterface().log(
                "Strings [Client] - Loaded " + stringsById.size() + " strings from " + files.length + " Files");
    } catch (IOException e) {
        PacketSamurai.getUserInterface().log("ERROR: Failed to load client_strings.xsd: " + e.toString());
        e.printStackTrace();
    }
}

From source file:Main.java

/**
 * Check how much usable space is available at a given path.
 *
 * @param path The path to check//from w ww  . j  a  v a2 s.c  om
 *
 * @return The space available in bytes
 */
public static long getUsableSpace(File path) {

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
        return path.getUsableSpace();
    }
    final StatFs stats = new StatFs(path.getPath());
    return (long) stats.getBlockSize() * (long) stats.getAvailableBlocks();
}

From source file:it.plugins.Project.java

public static Iterable<String> allFilesInDir(final String dirPath) {
    Collection<File> files = FileUtils.listFiles(new File(basedir(), dirPath), null, true);
    return from(files).transform(new Function<File, String>() {
        @Nullable/*from ww w .j  a v a 2 s. c o m*/
        public String apply(File file) {
            // transforms /absolute/path/to/src/java/Foo.java to src/java/Foo.java
            String filePath = FilenameUtils.separatorsToUnix(file.getPath());
            return dirPath + StringUtils.substringAfterLast(filePath, dirPath);
        }
    });
}

From source file:Main.java

/**
 * Check how much usable space is available at a given path.
 *
 * @param path The path to check//w w w .ja  v  a 2 s. c o  m
 * @return The space available in bytes
 */
@SuppressLint("NewApi")
public static long getUsableSpace(File path) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
        return path.getUsableSpace();
    }
    final StatFs stats = new StatFs(path.getPath());
    return (long) stats.getBlockSize() * (long) stats.getAvailableBlocks();
}