Mon Apr 22, 2013 10:57 pm
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLDecoder;
public class URLUtility {
public static String getFileFromURL(URL urlToDecode) {
String urlDecodedFilePath = urlToDecode.getFile();
String fixedFileString = null;
try { // Try to use 1.4 method with the recommended
//charset UTF-8
Class decoderClass = URLDecoder.class;
Method decodeMethod = decoderClass.getMethod("decode", new Class[] {
String.class , String.class });
Object fixedFileObject = decodeMethod.invoke(null, new Object[] {
urlDecodedFilePath, "UTF-8" });
fixedFileString = (fixedFileObject == null) ? null
: fixedFileObject.toString();
} catch (Exception e) { // Pre-1.4 version, no need to
//decode it.
fixedFileString = urlDecodedFilePath;
}
return (fixedFileString);
}
}
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com
Powered by phpBB © phpBB Group.