Java 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

StringmakePath(Collection files)
make Path
return makePath(files, File.pathSeparator);
voidmakePath(File copyTo)
make Path
File p = copyTo.getParentFile();
if (p == null) {
    return;
if (!p.exists()) {
    if (!p.mkdirs()) {
        throw new IOException("Could not create directory: " + p.getAbsolutePath());
StringmakePath(File cwd, String path)
make Path
String prefix = "", suffix = "";
if (path.startsWith("jar:file:")) {
    prefix = "jar:file:";
    int exclamation = path.indexOf('!');
    suffix = path.substring(exclamation);
    path = path.substring(prefix.length(), exclamation);
if (isAbsolutePath(path))
...
StringmakePath(final String dir, final String... jars)
make Path
StringBuilder sb = new StringBuilder();
for (String jar : jars) {
    if (sb.length() > 0)
        sb.append(File.pathSeparator);
    sb.append(dir).append(File.separator).append(jar);
return sb.toString();
voidmakePath(String basePath)
Makes folders along the specified path
File path = new File(basePath);
try {
    if (!path.exists()) {
        if (!path.mkdirs())
            if (!path.exists())
                throw new RuntimeException("Failed to create directory:" + basePath);
    } else if (!path.isDirectory()) {
        throw new RuntimeException("Something is already has this name, and it's not a dir: " + basePath);
...
StringmakePath(String filename, String savePath)
make Path
int hashcode = filename.hashCode();
int dir1 = hashcode & 0xf; 
int dir2 = (hashcode & 0xf0) >> 4; 
String dir = savePath + File.separator + dir1 + File.separator + dir2;
File file = new File(dir);
if (!file.exists()) {
    file.mkdirs();
    file.setWritable(true, false);
...
StringmakePath(String path1, String path2)
make Path
if (path1.endsWith(File.separator))
    return path1 + path2;
return path1 + File.separator + path2;
StringmakePath(String... elements)
Construct a file path from the given elements, i.e.
return String.join(File.separator, elements);
StringmakePath(String... elements)
Construct a file path from the given elements, i.e.
return join(File.separator, elements);
StringmakePath(String[] strings)
Convert a list of path elements to a platform-specific path.
String result = "";
for (int i = 0; i < strings.length; i++)
    result += File.separator + strings[i];
return result;