I try to get the path
to the directory my class is in. That works fine. But I want to edit this path like this. Example:
Take this path:
/C:/User/Folder1/bin/
I want to change above path to this:
C:\\User\\Folder1\\bin\\
Now, I have written this code to accomplish this:
path = StartUp.class.getProtectionDomain().getCodeSource().getLocation().getPath();
decodedPath = URLDecoder.decode(path, "UTF-8");
System.out.println(path);
System.out.println(decodedPath);
pathArray = decodedPath.split("/");
pathLength = pathArray.length;
int x = 1;
while(x <= pathLength){
goodPath = goodPath + pathArray[x] + "\\";
x++;
}
System.out.println("goodPath " + goodPath);
System.out.println(decodedPath);
I thought this would accomplish it, but all output I get is:
/C:/User/Folder1/bin/
/C:/User/Folder1/bin/
5
For some reason it displays the number of elements in pathArray
and skips the last two System.out.println()
's.
Does anyone know what is going on here?