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 getFileExtension(String filePath) {
    if (TextUtils.isEmpty(filePath)) {
        return filePath;
    }//from  www  .  j a v a  2  s  .c  o m

    int extenPosi = filePath.lastIndexOf(FILE_EXTENSION_SEPARATOR);
    int filePosi = filePath.lastIndexOf(File.separator);
    if (extenPosi == -1) {
        return "";
    }
    return (filePosi >= extenPosi) ? "" : filePath.substring(extenPosi + 1);
}

From source file:Main.java

/**
 * Get parent path of file/*from  w  ww.  j ava 2 s  .  c  om*/
 * 
 * @param p_absoluteFilename
 *            The file name with absolute path
 * @return String Parent path
 * 
 * @version 1.0
 * @since 8.2.2
 */
private static String getBaseAbsoluatePath(String p_absoluteFilename) {
    return p_absoluteFilename.substring(0, p_absoluteFilename.lastIndexOf(File.separator));
}

From source file:Main.java

/**
 * Constructs a path name to a unique temporary file within the caches'
 * temporary sub-directory./*  ww w. j  a v  a 2 s.c om*/
 *
 * @return Application temporary sub-directory path.
 */
public static String getTempDirPathName(Context context) {
    return getCacheDirPathName(context) + File.separator + TEMP_DIRNAME;
}

From source file:AIR.Common.Utilities.Path.java

public static String combine(String dir, String fileName) {
    return combine(dir, fileName, File.separator);
}

From source file:Main.java

public static Uri getOutputImageFileURL() {
    Log.d(LOG_MESSAGE, "external dir:"
            + Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).getAbsolutePath());
    File mediaStorageDir = new File(
            Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), IMAGE_DIRECTORY);
    if (!mediaStorageDir.exists()) {
        if (!mediaStorageDir.mkdirs()) {
            Log.d(LOG_MESSAGE, "failed to create directory");
            return null;
        }//  w ww . j a  va2  s. c o m
    }
    String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
    File mediaFile = new File(mediaStorageDir.getAbsolutePath() + File.separator + "IMG_" + timeStamp + ".png");
    return Uri.fromFile(mediaFile);
}

From source file:Main.java

/**
 * Get the main name of specified file/*w ww  . j  a va2  s .co m*/
 * 
 * @param p_absoluteFilename
 *            The file name with absolute path
 * @return String Main name of file
 * 
 * @version 1.0
 * @since 8.2.2
 */
private static String getMainFilename(String p_absoluteFilename) {
    return p_absoluteFilename.substring(p_absoluteFilename.lastIndexOf(File.separator) + 1);
}

From source file:Main.java

public static String getFileNameWithoutExtension(String filePath) {
    if (TextUtils.isEmpty(filePath)) {
        return filePath;
    }//w w  w .j  a v a 2  s .  c om

    int extenPosi = filePath.lastIndexOf(FILE_EXTENSION_SEPARATOR);
    int filePosi = filePath.lastIndexOf(File.separator);
    if (filePosi == -1) {
        return (extenPosi == -1 ? filePath : filePath.substring(0, extenPosi));
    }
    if (extenPosi == -1) {
        return filePath.substring(filePosi + 1);
    }
    return (filePosi < extenPosi ? filePath.substring(filePosi + 1, extenPosi)
            : filePath.substring(filePosi + 1));
}

From source file:Main.java

public static File getOutputMediaFile(Context context, String mediaName) {
    File mediaStorageDir = null;//from w w w  .jav  a2s . co  m
    try {
        mediaStorageDir = new File(context.getExternalFilesDir(Environment.DIRECTORY_PICTURES), ImgFolderName);
    } catch (Exception e) {
        e.printStackTrace();
    }

    if (!mediaStorageDir.exists()) {
        if (!mediaStorageDir.mkdirs()) {
            return null;
        }
    }

    File mediaFile = new File(mediaStorageDir.getPath() + File.separator + mediaName);
    return mediaFile;
}

From source file:Main.java

public static String getWebDbFolder(String appName) {
    String path = getDataFolder(appName) + File.separator + WEB_DB_FOLDER_NAME;
    return path;
}

From source file:Main.java

public static String toAppPath(String fullpath) {
    String path = getOdkFolder() + File.separator;
    if (fullpath.startsWith(path)) {
        String partialPath = fullpath.substring(path.length());
        String[] app = partialPath.split(File.separator);
        if (app == null || app.length < 1) {
            Log.w(t, "Missing file path (nothing under '" + ODK_FOLDER_NAME + "'): " + fullpath);
            return null;
        }/*from  www. ja  v  a 2 s  .  c om*/
        return partialPath;
    } else {

        String[] parts = fullpath.split(File.separator);
        int i = 0;
        while (parts.length > i && !parts[i].equals(ODK_FOLDER_NAME)) {
            ++i;
        }
        if (i == parts.length) {
            Log.w(t, "File path is not under expected '" + ODK_FOLDER_NAME + "' Folder (" + path
                    + ") conversion failed for: " + fullpath);
            return null;
        }
        int len = 0; // trailing slash
        while (i >= 0) {
            len += parts[i].length() + 1;
            --i;
        }

        String partialPath = fullpath.substring(len);
        String[] app = partialPath.split(File.separator);
        if (app == null || app.length < 1) {
            Log.w(t, "File path is not under expected '" + ODK_FOLDER_NAME + "' Folder (" + path
                    + ") missing file path (nothing under '" + ODK_FOLDER_NAME + "'): " + fullpath);
            return null;
        }

        Log.w(t, "File path is not under expected '" + ODK_FOLDER_NAME + "' Folder -- remapped " + fullpath
                + " as: " + path + partialPath);
        return partialPath;
    }
}