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.mirth.connect.util.FilenameUtils.java

public static String getAbsolutePath(File baseDir, String path) {
    path = StringUtils.trim(path);/*from   ww  w. j av a 2  s  .  co m*/
    File file = new File(path);

    if (file.isAbsolute()) {
        return file.getPath();
    }

    char firstChar = path.charAt(0);

    /*
     * For Windows systems, if the path begins with a forward or back slash, extract the drive
     * letter from baseDir and use the drive's root directory as the new baseDir.
     */
    if (firstChar == '/' || firstChar == '\\') {
        File parent = baseDir.getParentFile();

        while (parent != null) {
            baseDir = parent;
            parent = baseDir.getParentFile();
        }

        return new File(baseDir, path).getAbsolutePath();
    }

    return new File(baseDir, path).getAbsolutePath();
}

From source file:Main.java

public static Bitmap originalImg(File file) {
    Bitmap resizeBmp = null;/*from   ww w  .  java 2  s . c  o m*/
    try {
        resizeBmp = BitmapFactory.decodeFile(file.getPath());
    } catch (Exception e) {
        e.printStackTrace();
    }
    return resizeBmp;
}

From source file:Main.java

public static String getImagePathInExternalStoragePublicDirectory(String filename) {

    File path = Environment.getExternalStoragePublicDirectory("uDrove");
    File file = new File(path, filename + ".jpg");
    path.mkdirs();//  w  w w  . j  a v a  2s  .  c o m

    if (file.exists()) {

        return file.getPath();
    }

    return "";
}

From source file:Main.java

/**
 * @return Available external memory// w  w  w  .  j  a  va 2 s  .  co  m
 */
public static int getAvailableExternalMemorySize() {
    if (isExternalStorageAvailable()) {
        File path = Environment.getExternalStorageDirectory();
        StatFs stat = new StatFs(path.getPath());
        int blockSize = stat.getBlockSize();
        int availableBlocks = stat.getAvailableBlocks();
        return availableBlocks * blockSize;
    } else {
        return 0;
    }
}

From source file:Main.java

public static List<String> listFilePath(File file) {
    List<String> list = new ArrayList<String>();
    for (File childFile : listFile(file)) {
        list.add(childFile.getPath());
    }//from  w w w  .  j a v  a  2 s.  com
    return list;
}

From source file:Main.java

public static List<String> listFilePath(String path) {
    List<String> list = new ArrayList<String>();
    for (File childFile : listFile(path)) {
        list.add(childFile.getPath());
    }/*from w  ww  .j  a  v a 2 s .c  om*/
    return list;
}

From source file:Main.java

public static long getAvailableExternalSpace() {
    File path = new File(Environment.getExternalStorageDirectory().getAbsolutePath());
    StatFs stat = new StatFs(path.getPath());
    long blockSize = stat.getBlockSize();
    long availableBlocks = stat.getAvailableBlocks();
    return availableBlocks * blockSize;
}

From source file:Main.java

public static boolean hasEnoughSpace(float needSize) {
    if (isSDCardExist()) {
        File path = Environment.getExternalStorageDirectory();
        StatFs sf = new StatFs(path.getPath());

        long blockSize;
        long availCount;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
            blockSize = sf.getBlockSizeLong();
            availCount = sf.getAvailableBlocksLong();
        } else {//from   ww  w .  j a va 2 s .  c  o  m
            blockSize = sf.getBlockSize();
            availCount = sf.getAvailableBlocks();
        }

        long restSize = availCount * blockSize;
        if (restSize > needSize) {
            return true;
        }
    }
    return false;
}

From source file:Main.java

public static String getExternalCacheDir(Context context) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO) {
        File f1 = context.getExternalCacheDir();
        if (f1 != null) {
            return f1.getPath();
        } else {//from w  w w .  j a  v a  2  s.  c o m
            return null;
        }
    } else {
        final String cacheDir = "/Android/data/" + context.getPackageName() + "/cache/";
        File f2 = Environment.getExternalStorageDirectory();
        if (f2 != null) {
            return f2.getPath() + cacheDir;
        } else {
            return null;
        }
    }
}

From source file:edu.cuhk.hccl.Indexer.java

/**
 * Create index of RAMDirectory from a data folder with text files
 * /*from  w w w  .  jav a 2  s  . com*/
 * @param dataSet
 * @throws IOException
 */
public static void createIndex(String dataSet) throws IOException {
    IndexWriterConfig config = new IndexWriterConfig(Version.LATEST, analyzer);
    IndexWriter writer = new IndexWriter(index, config);

    Collection<File> files = FileUtils.listFiles(new File(dataSet), null, true);
    for (File file : files) {
        String path = file.getPath();
        String content = FileUtils.readFileToString(file);

        Document doc = new Document();

        doc.add(new StringField(PATH_FIELD, path, Field.Store.YES));
        doc.add(new Field(CONTENT_FIELD, content, TERM_STORED));

        writer.addDocument(doc);

        System.out.println("[INFO] Indexing file: " + path);
    }

    System.out.println("\n[INFO]" + files.size() + " files has been indexed.");

    writer.close();
}