Android Utililty Methods Path Create

List of utility methods to do Path Create

Description

The list of methods to do Path Create are organized into topic(s).

Method

StringensureSlash(String dirPath)
ensure Slash
if (dirPath.endsWith(File.separator)) {
    return dirPath;
return dirPath + File.separator;
StringfileDir(String filename)
file Dir
String path = null;
if (!FileUtil.isFileExist(filename)) {
    File f = new File(filename);
    f.mkdir();
    path = f.getPath();
return path;
StringfileDir(String folder, String folderName)
file Dir
String path = null;
if (!FileUtil.isFileExist(folder, folderName)) {
    String fullPath = folder + folderName;
    File f = new File(fullPath);
    f.mkdir();
    path = f.getPath();
return path;
...
FilegetAbsoluteFile(String filename, String basedir)
Gets an absolute file from a filename.
if (filename == null) {
    return null;
File file = new File(filename);
if (file.isAbsolute()) {
    return file;
} else {
    return new File(basedir, file.getPath());
...
StringgetAbsolutePath(String strCurrenDir, String strFileName)
get Absolute Path
if (!strFileName.startsWith("/") && !strFileName.startsWith("\\")) {
    if (!strCurrenDir.endsWith("/") && !strCurrenDir.endsWith("\\"))
        return strCurrenDir + "/" + strFileName;
    return strCurrenDir + strFileName;
return strFileName;
StringgetAbsolutePathFromResource(Class reference, String resource)
Returns the absolute path of the resource.
URL urlResource = reference.getResource(resource);
if (urlResource == null)
    return null;
String urlString = URLDecoder.decode(urlResource.toString());
if (urlString.startsWith("jar:"))
    urlString = urlString.substring("jar:".length());
if (urlString.startsWith("file:"))
    urlString = urlString.substring("file:".length());
...
StringgetAbsolutePathFromResource(String resource)
Returns the absolute path of the resource.
return getAbsolutePathFromResource(Object.class, resource);
StringgetCanonicalPath(File file)
get Canonical Path
try {
    return file.getCanonicalPath();
} catch (Exception e) {
return null;
String[]getDirAndFullName(File f)
get Dir And Full Name
String path = f.getPath();
int index = path.lastIndexOf('/');
if (index == -1) {
    index = path.lastIndexOf('\\');
return new String[] { path.substring(0, index + 1),
        path.substring(index + 1) };
StringgetDirName(String dir)
get Dir Name
if (dir.endsWith(separator)) {
    dir = dir.substring(0, dir.lastIndexOf(separator));
return dir.substring(dir.lastIndexOf(separator) + 1);