Example usage for java.io File separator

List of usage examples for java.io File separator

Introduction

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

Prototype

String separator

To view the source code for java.io File separator.

Click Source Link

Document

The system-dependent default name-separator character, represented as a string for convenience.

Usage

From source file:Main.java

public static void creatFile(String fileName) {
    if (sdState.equals(Environment.MEDIA_MOUNTED)) {
        File file = new File(
                Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + fileName);
        if (!file.exists()) {
            file.mkdir();/*from  ww  w.j a v a  2 s .c  o  m*/
        }
    }
}

From source file:Main.java

public static File getFileName(String dirPath, String fileName, Context context) {
    File mLogDir;/* w ww.  java 2s  . co m*/
    if (isSDCardAvailable()) {
        mLogDir = new File(
                Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + dirPath);
    } else {
        mLogDir = new File(context.getFilesDir().getAbsolutePath() + File.separator + dirPath);
    }
    if (!mLogDir.exists()) {
        mLogDir.mkdirs();
    }
    return new File(mLogDir.getAbsolutePath() + File.separator + fileName);
}

From source file:Main.java

private static void decompressGzipFile(String gzipFile) {
    try {//from w w w.java 2s .  com
        File newFile = new File(Environment.getExternalStorageDirectory() + File.separator + "FlockLoad");
        FileInputStream fis = new FileInputStream(gzipFile);
        GZIPInputStream gis = new GZIPInputStream(fis);
        FileOutputStream fos = new FileOutputStream(newFile);
        byte[] buffer = new byte[1024];
        int len;
        while ((len = gis.read(buffer)) != -1) {
            fos.write(buffer, 0, len);
        }
        //close resources
        fos.close();
        gis.close();
    } catch (IOException e) {
        e.printStackTrace();
    }

}

From source file:Main.java

public static File createSDFile(String dir, String fileName) {
    File file = new File(dir + File.separator + fileName);
    try {// w ww.j  a  v  a2  s.c  o  m
        file.createNewFile();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return file;
}

From source file:Main.java

@SuppressLint("NewApi")
public static long getSDCardAvailableSize() {
    if (isSDCardEnable()) {
        StatFs statFs = new StatFs(
                Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator);
        if (android.os.Build.VERSION.SDK_INT < 18) {
            int blockSize = statFs.getBlockSize();
            int blockCount = statFs.getAvailableBlocks();
            return blockCount * blockSize;
        } else {/*from   w w  w .  j  a  v  a2s  .c o m*/
            long blockSize = statFs.getBlockSizeLong();
            long blockCount = statFs.getAvailableBlocksLong();
            return blockCount * blockSize;
        }
    }
    return -1;
}

From source file:Main.java

private static String getSDDir(String key_dir) {
    StringBuilder sb = new StringBuilder();
    String absolutePath = Environment.getExternalStorageDirectory().getAbsolutePath();// /mnt/sdcard
    sb.append(absolutePath);/*from  w ww .  j av a2 s.c om*/
    sb.append(File.separator).append(ROOT_DIR).append(File.separator).append(key_dir);

    String filePath = sb.toString();
    File file = new File(filePath);
    if (!file.exists()) {
        if (file.mkdirs()) {
            return file.getAbsolutePath();
        } else {
            return "";
        }
    }

    return file.getAbsolutePath();
}

From source file:Main.java

public static String getImageSavePath(String fileName) {

    if (TextUtils.isEmpty(fileName)) {
        return null;
    }//from   w  ww  .  j  av  a  2  s.c o  m

    final File folder = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator
            + "MGJ-IM" + File.separator + "images");
    if (!folder.exists()) {
        folder.mkdirs();
    }

    return folder.getAbsolutePath() + File.separator + fileName;
}

From source file:Main.java

private static float getSize(String path, Float size) {
    File file = new File(path);
    if (file.exists()) {
        if (file.isDirectory()) {
            String[] children = file.list();
            for (int fileIndex = 0; fileIndex < children.length; ++fileIndex) {
                float tmpSize = getSize(file.getPath() + File.separator + children[fileIndex], size) / 1000;
                size += tmpSize;/*  ww  w.ja va2  s . c o m*/
            }
        } else if (file.isFile()) {
            size += file.length();
        }
    }
    return size;
}

From source file:Main.java

private static File generateMessagePath(String var0, String var1, Context context) {
    File file = new File(generateHistoryPath(var0, var1, context), var1 + File.separator + "Msg.db");
    return file;/*from ww w . j  ava 2  s.c  o  m*/
}

From source file:Main.java

public static Bitmap readImageFile(String fileName) {
    if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
        return null;
    }/*  w w w. j  av  a 2 s  .  c  om*/
    File file = new File(Environment.getExternalStorageDirectory().toString() + File.separator + fileName);
    if (!file.exists()) {
        return null;
    }
    return BitmapFactory.decodeFile(fileName);
}