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 File getSaveFolder(String folderName) {
    File file = new File(Environment.getExternalStorageDirectory().getAbsoluteFile() + File.separator
            + folderName + File.separator);
    file.mkdirs();//  w  ww . ja  v  a2s.  c o  m
    return file;
}

From source file:Main.java

public static String getDataDirectory(Context context) {
    File sdRoot = Environment.getExternalStorageDirectory();
    String path = sdRoot.getPath();
    String packageName = context.getPackageName();
    path = path + File.separator + "Android" + File.separator + "data" + File.separator + packageName
            + File.separator + "files" + File.separator;
    return path;//from   w w  w .  j ava2  s.  c  o  m
}

From source file:Util.java

public static String getFilesystemPathFromDate(Date date) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);/* w ww.  ja  v a2 s  . co  m*/
    NumberFormat format = new DecimalFormat("00");
    return File.separator + format.format(calendar.get(Calendar.YEAR)) + File.separator
            + format.format((calendar.get(Calendar.MONTH) + 1)) + File.separator
            + format.format(calendar.get(Calendar.DAY_OF_MONTH)) + File.separator;
}

From source file:Main.java

public static String getOutputFilePath(File directory, String extension) throws IOException {
    ensureDirExists(directory);/*from  www  .jav a 2 s. c  o m*/
    String filename = UUID.randomUUID().toString();
    return directory + File.separator + filename + extension;
}

From source file:Main.java

public static String readFileText(Context context, String fileName, boolean deleteFile) {
    File root = new File(context.getExternalFilesDir(null) + File.separator);
    File file = new File(root, "." + fileName);

    StringBuilder text = new StringBuilder();

    if (file.exists()) {
        try {/*from   w  ww  .ja v  a  2s .  c om*/
            BufferedReader br = new BufferedReader(new FileReader(file));
            String line;

            while ((line = br.readLine()) != null) {
                text.append(line);
                text.append('\n');
            }

            br.close();

            if (deleteFile)
                file.delete();
        } catch (IOException e) {

        }
    } else {
        text.append("File not exists");
    }

    return text.toString();
}

From source file:Main.java

/**
 * get all the log files to upload// w  ww . jav  a 2  s .  co  m
 * 
 * @return
 */
public static File[] getFilesToUpload() {
    File[] files = null;
    File directory = new File(Environment.getExternalStorageDirectory() + File.separator + folderName);
    if (directory.exists()) {
        files = directory.listFiles();
    }
    return files;
}

From source file:Main.java

public static File getExtWorkingDir(Context context) {
    if (!isExternalStorageWritable())
        return null;
    File workingDir = new File(Environment.getExternalStorageDirectory() + File.separator + "data");
    if (!workingDir.exists())
        workingDir.mkdir();/*from  ww w . j  av  a 2s  .c  o  m*/
    workingDir = new File(workingDir + File.separator + getPackageName(context));
    if (!workingDir.exists())
        workingDir.mkdir();
    return workingDir;
}

From source file:Main.java

public static String getFileNameFromURL(String s) {
    if (s == null) {
        return null;
    }/*w w w.ja v  a 2s .c om*/
    String s1 = URLDecoder.decode(s);
    if (s1.indexOf("?") >= 0) {
        s1 = s1.substring(0, s1.indexOf("?"));
    }
    return s1.substring(1 + s1.lastIndexOf(File.separator), s1.length());
}

From source file:Main.java

public static void debugLsDir(String dir) {
    File directory = new File(dir);
    Log.d("quran_dbg", directory.getAbsolutePath());

    if (directory.isDirectory()) {
        String[] children = directory.list();
        for (String s : children)
            debugLsDir(dir + File.separator + s);
    }/*from  ww  w.  j  a v  a  2 s .  c o  m*/
}

From source file:Main.java

/**
 *  Get path to with out root directory/* w  w  w.  ja  va2s  . c o m*/
 *  @param rootDir - root directory
 *  @param path - full path
 *  @return string to show current path
 */
public static final String getLabelPath(String rootDir, String path) {
    String result = "";
    if (path == null) {
        result = File.separator;
    } else {
        result = path.replace(rootDir, "");
    }
    return result;
}