I have two strings. One names a folder's absolute (or relative) path. The other names a file name with potentially unsafe characters:
String folder = "C:\a\b\c\dir";
Sting file = "file name: contains-unsafe_characters?" + ".txt"
I want to smash these to strings together literally in the form:
String absPath = folder + SYSTEM_INDEPENDENT_PATH_SEPERATOR + convertToPercentOctal(folder);
Now, there are probably one million approaches to try to do this:
UriBuilder folderBuilder = UriBuilder.fromPath(folder);
UriBuilder fileBuilder = UriBuilder.fromPath(file);
URI completeFileName = folderBuilder.build().resolve(fileBuilder.build());
or:
URI completeFileName = UriBuilder.fromPath(folder).path(file).build();
etc.
The first block of code fails because there may be a : in the file name. If that is the case, UriBuilder will try to parse it as the optional scheme:. The second way fails because it returns the first and second half converted to %octal notation separated by a system dependent '/' character.
Is there a way concatenate a two strings, convert the result to a writable file name, and return a valid URI I can use to create the file?