Originally Posted by
Norm
Can you explain what the objective of your code is?
Here's simple code to replace the %20 with a blank.
Your code already does it. I don't understand what the regex if for.
The intent here is to obtain what amounts to File.toString() - or more correctly
/** C:\src_jdk1.5.0_12\java\io\File.java
* An abstract representation of file and directory pathnames.
*/
String locationOnRemoteServer = new String(File.getName());//
String locationOnRemoteServer = new String(File.getAbsolutePath());//
String locationOnRemoteServer = new String(File.getCanonicalPath());//
String locationOnRemoteServer = new String(File.getAbsolutePath());//
/**
* Avoiding somehow: /**
*
* "The exact form of the URI is system-dependent."
*/
Running your code with as few changes as I could ( moved it to an instance method to use the this pointer as you did ), I get:
string=FileDog, user.dir=C:\Documents and Settings\All Users\Documents
url=file:/C:/Documents%20and%20Settings/Owner/.Arachnophilia/CustomClasses/FileDog.class
decode= file:/C:/Documents and Settings/Owner/.Arachnophilia/CustomClasses/FileDog.class
defaultCharacterSet = windows-1252
decode2=file:/C:/Documents and Settings/Owner/.Arachnophilia/CustomClasses/FileDog.class
file:/C:/Documents%20and%20Settings/Owner/.Arachnophilia/CustomClasses/FileDog.class
Which shows an equivilant last line:
file:/D:/JavaDevelopment/Testing/JavaForum/Folder%20with%20blanks/FindPathToFile.class
Thus appears to me to be the same result of Matcher finding escape codes in a string that was supposed to be decoded, no?
The inclusion of ", user.dir=" + System.getProperty("user.dir")); in your sample provides an appealing avenue of exploration. For the short version of what my code intends to do we can take Jason Weiss' ISBN:0-12-742751-1 contradistincted to the front pages of the news today and surmise that I should write code I understand.
Thus, a simple replacement of %20 to find /WEB-INF/ in a File.getWhereIt'sAt() should yield to a lib method, URL.decode(), that is documented to return a string.
Doing a regex work on the String should not in my opinion result in an optimized version that defeated the intent of:
String URLStr = url.toString();
if(URLStr.indexOf(Percent) >= 0) {
URLStr = URLDecoder.decode(URLStr, "UTF8");
System.out.println("decode= " + URLStr);
Which we would ( I would think ) do
URLDecoder.decode(URLStr, "UTF8"); directly on the result of
sb.append(/*FileDog.*/this.getClass().getResource("/" + string + ".class")); probably thus:
Matcher matcher = Pattern.matcher(URLDecoder.decode(this.getClass().getResource("/" + string + ".class", "UTF8")));//
The intent of that being to find /WEB-INF/ or some descendent folder or dir such that a conventional File may be written and thus ftp'd or used in a Servlet such that the application works in a manner I understand.
I sure do not understand what .class is doing in all this.