I am currently writing a function to upload files into server.
My filename format is typical like this ACTION#USERNAME.TXT, I run into the error
java.lang.StringIndexOutOfBoundsException: length=41; regionStart=38; regionLength=-28
when on this line of code
writer.append("Content-Type: " + URLConnection.guessContentTypeFromName(fileName)).append(LINE_FEED);
# sign has special meaning in a URL.
#fragment part of a URL (see syntax) is never sent from the client to the server. It is a part of the URL that is handled by the client. It can be sent from the server to the client in links and redirects.
To include a
# sign (or any other special character) in the file name, it must be escaped/encoded using
%NN hex codes.
The encoding of
%23, but you really should use a URL encoder.