I have a code example which creates paths like this :
String path = System.getProperty("user.dir") + File.separator + "games" + File.separator + "game.exe";
It is irritating and difficult to type File.separator
repeatedly. Is there a shorter way to create the path ? I created a custom function to do that, but I am not sure if it is the right way. Please advise.
//Ex. getPath("downloads", "games", "racing.exe") ---> \downloads\games\racing.exe
public static String getPath(String...pathFragments){
StringBuilder sb = new StringBuilder(File.separator);
for(int i = 0; i < pathFragments.length-1; i++){
sb.append(pathFragments[i] + File.separator);
}
//Append last pathFragment.
sb.append(pathFragments[pathFragments.length-1]);
return sb.toString();
}