Java Utililty Methods Path Convert To

List of utility methods to do Path Convert To

Description

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

Method

StringfilePathToClassNameOrNull(String filePathWithExtension)
Return the class name of the given java source or class file as suggested by the file path, or null if the class name could not be determined
if (filePathWithExtension.endsWith(".java") || filePathWithExtension.endsWith(".class")) {
    String classPath = stripExtension(filePathWithExtension);
    String className = filePathToClassPath(classPath);
    return className;
return null;
StringfilePathToClassPath(String path)
file Path To Class Path
path = toForwardSlashes(path);
if (path.charAt(0) == '/') {
    path = path.substring(1);
return path.replace('/', '.');
StringfilePathToJavaBinaryName(final String filePath, final String separator)
file Path To Java Binary Name
return filePath.substring(0, filePath.length() - 6).replace(separator, ".");
StringfilePathToPackagePathOrNull(String path)
Return the package name part of the given file path or null if no package name could be determined
path = toForwardSlashes(path);
if (path.charAt(0) == '/') { 
    path = path.substring(1);
int last = path.lastIndexOf('/');
if (last == -1) { 
    return null;
String pkg = path.substring(0, last); 
pkg = pkg.replace('/', '.');
if (pkg.length() == 0) {
    return null;
return pkg;
StringfilePathToUrl(String filePath)
Transforms an absolute file path in the local file system into a URL-compatible address for the file.
if (filePath.startsWith("/")) {
    return "file://" + filePath;
} else {
    return "file:///" + filePath;
StringpathTo(String filename)
path To
String result = "";
int p = filename.lastIndexOf('/');
if (p >= 0) {
    result = filename.substring(0, p);
return result;
StringpathTo(String ref)
returns the path to a instance node (i.e.
if (ref != null) {
    int pos = ref.lastIndexOf("/");
    if ((pos == -1) || (pos == 0)) {
        return null;
    return ref.substring(0, pos);
return null;
...
voidpathToAdjacencyList(final int[] path, final int[] adjacencyList)
Convert a solution from path representation to adjacency representation .
int last;
last = path[path.length - 1];
for (final int p : path) {
    adjacencyList[last - 1] = p;
    last = p;
StringpathToClassName(String path)
Converts a path to class name, i.e., replaces "/" by "."
return path.substring(0, path.length() - 6).replace("/", ".");
StringpathToClassName(String pathName)
path To Class Name
return pathName.replace('/', '.').replace('\\', '.');