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 String getDownAudioPath(Context context, String url) {
    String fileName = url.substring(url.lastIndexOf("/") + 1);
    File mediaStorageDir = new File(context.getExternalFilesDir(Environment.DIRECTORY_RINGTONES),
            AudioFolderName);//w w  w  .j  a  v a  2  s .  c o m

    return mediaStorageDir.getPath() + File.separator + fileName;
}

From source file:Main.java

public static File getMultimediaDirectory() {
    File multimediaDirectory = new File(Environment.getExternalStorageDirectory() + File.separator
            + "LiteracyApp" + File.separator + "multimedia");
    if (!multimediaDirectory.exists()) {
        multimediaDirectory.mkdirs();/*from   w ww. j  ava2s .c  o  m*/
    }
    return multimediaDirectory;
}

From source file:Main.java

private static void copyFile(AssetManager assetManager, String filename, String destination) {
    InputStream in = null;//ww  w  . ja va2  s  . com
    OutputStream out = null;
    try {
        in = assetManager.open(filename);
        String newFileName = destination + File.separator + filename;
        out = new FileOutputStream(newFileName);

        byte[] buffer = new byte[1024];
        int read;
        while ((read = in.read(buffer)) != -1) {
            out.write(buffer, 0, read);
        }
        in.close();
        in = null;
        out.flush();
        out.close();
        out = null;
    } catch (Exception e) {
        Log.e("tag", e.getMessage());
    }
}

From source file:Main.java

public static InputStream loadAsset(Context context, String path, String filename) {
    AssetManager assetManager = context.getResources().getAssets();
    InputStream inputStream = null;

    try {/*from   www  .  ja  va  2  s .c o  m*/
        String fullFilename = path + File.separator + filename;
        inputStream = assetManager.open(fullFilename);
        if (inputStream != null)
            Log.d("AssetsUtil", "Loaded " + fullFilename);
    } catch (IOException e) {
        e.printStackTrace();
    }
    return inputStream;
}

From source file:Main.java

public static File getDiskDir(String uniqueName) {
    if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())
            || !Environment.isExternalStorageRemovable()) {
        File storageDirectory = Environment.getExternalStorageDirectory();
        if (storageDirectory != null) {
            File file = new File(storageDirectory + File.separator + uniqueName);
            if (!file.exists() && !file.isDirectory()) {
                file.mkdir();/*from   ww w.  ja  va2  s  . com*/
            }
            return file;
        }
    }
    return null;
}

From source file:Main.java

/**
 * combine two path into a single path with File.separator.
 * Handle all cases where the separator already exists.
 *//* w ww  .j a  v a2  s. co m*/
public static String pathCombine(String path1, String path2) {
    if (path2 == null)
        return path1;
    else if (path1 == null)
        return path2;

    path1 = path1.trim();
    path2 = path2.trim();
    if (path1.endsWith(File.separator)) {
        if (path2.startsWith(File.separator))
            return path1 + path2.substring(1);
        else
            return path1 + path2;
    } else {
        if (path2.startsWith(File.separator))
            return path1 + path2;
        else
            return path1 + File.separator + path2;
    }
}

From source file:Main.java

/** 
 *create the zip file path//from  www.  j av a2s  . co m
 */
private static String buildDestinationZipFilePath(File srcFile, String destParam) {
    createDestDirectoryIfNecessary(destParam);

    String fileName = "";
    if (srcFile.isDirectory()) {
        fileName = srcFile.getName();
    } else {
        fileName = srcFile.getName().substring(0, srcFile.getName().lastIndexOf("."));
    }

    if (destParam.endsWith(File.separator)) {
        destParam += fileName + ".zip";
    } else {
        destParam += File.separator + fileName + ".zip";
    }
    // }  
    return destParam;
}

From source file:Main.java

public static String getSaveImagePath(Context context) {
    String path = getCacheDir(context).getAbsolutePath();
    if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
        path = Environment.getExternalStorageDirectory().getAbsolutePath();
    }//from w  w  w  . java2s .c  om

    path = path + File.separator + "Pictures";
    File file = new File(path);
    if (!file.exists()) {
        file.mkdir();
    }
    return path;
}

From source file:Main.java

public static String getCachePath(Context context, String uniqueName) {
    String cachePath;/*  w  w w  .  j a v a2s. c  o m*/
    if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())
            || !Environment.isExternalStorageRemovable()) {
        cachePath = context.getExternalCacheDir().getPath();
    } else {
        cachePath = context.getCacheDir().getPath();
    }
    return cachePath + File.separator + uniqueName;
}

From source file:DirectoryTree.java

public static void tree(String filename) {
    File file = new File(filename);

    if (!file.isDirectory()) {
        System.out.println(filename);
        return;/*from   ww w  . j  a  va 2s  .  c o m*/
    }

    String files[] = file.list();
    for (int i = 0; i < files.length; i++) {
        tree(filename + File.separator + files[i]);
    }
}