Java Utililty Methods File Path Create

List of utility methods to do File Path Create

Description

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

Method

StringbuildPath(final boolean endWithSep, final String... val)
Build a path out of the given elements.
StringBuilder path = new StringBuilder();
for (String s : val) {
    if (s != null) {
        path.append(s);
String s = path.toString().replaceAll("/+", "/");
if (endWithSep) {
...
StringbuildPath(final String basePath, final String path)
build Path
if (basePath == null && path == null) {
    return "";
if (basePath == null) {
    return path;
if (path == null) {
    return basePath;
...
StringbuildPath(final String... tokens)
build Path
final StringBuilder sb = new StringBuilder();
for (final String token : tokens) {
    sb.append(TOKEN_PATH_SEPARATOR).append(token);
return sb.toString();
StringbuildPath(Integer sAccountId, String objectPath)
build Path
return ((sAccountId == null) ? "" : sAccountId + "/") + objectPath;
StringbuildPath(long id, boolean justDir)
build Path
StringBuilder fileBuffer = new StringBuilder();
fileBuffer.append(id);
while ((fileBuffer.length() % 3) != 0) {
    fileBuffer.insert(0, '0');
StringBuilder dirBuffer = new StringBuilder();
for (int i = 0; i < fileBuffer.length() - 3; i += 3) {
    dirBuffer.append(fileBuffer.subSequence(i, i + 3));
...
StringbuildPath(String first, String... parts)
Concatenate path parts into a full path, taking care of extra or missing slashes.
String result = first;
for (String part : parts) {
    if (result.isEmpty()) {
        if (part.startsWith("/")) {
            result += part.substring(1);
        } else {
            result += part;
    } else {
        if (result.endsWith("/") && part.startsWith("/")) {
            result += part.substring(1);
        } else if (!result.endsWith("/") && !part.startsWith("/") && !part.isEmpty()) {
            result += "/" + part;
        } else {
            result += part;
return result;
StringbuildPath(String part1, String part2)
Takes two strings as input and builds a valid path out of them by placing a slash inbetween them.
String retVal;
if (part1.endsWith("/") && part2.startsWith("/")) {
    part1 = part1.substring(0, part1.length() - 1);
    retVal = part1 + part2;
} else if (!part1.endsWith("/") && !part2.startsWith("/")) {
    retVal = part1 + "/" + part2;
} else
    retVal = part1 + part2;
...
StringbuildPath(String path, String file)
build Path
if (path == null || path.isEmpty())
    return file;
else
    return path + "/" + file;
StringbuildPath(String... paths)
Concatenates multiple string values together, ensuring that each value consists of only forward slashes.
StringBuilder finalPath = new StringBuilder();
for (String path : paths) {
    path = path.replace("\\", "/");
    if (finalPath.length() > 0) {
        if (finalPath.charAt(finalPath.length() - 1) != '/') {
            finalPath.append("/");
        if (path.length() > 0 && path.charAt(0) == '/') {
...
StringbuildPath(String... strings)
Builds a file path by concatenating the single strings and separating them with the system specific file separator character.
StringBuilder sb = new StringBuilder();
for (String s : strings) {
    if (sb.length() != 0)
        sb.append(System.getProperty("file.separator"));
    sb.append(s);
return sb.toString();