如果我想在 Java 中传递以下 URL:
\n\n
...我应该用什么句柄来处理字符串。
\n\n到目前为止,我无法处理该字符串,我所拥有的只是???字符。
\n\n谢谢。
\n\n2012年9月9日修改:
\n\npackage pruebas;\n\nimport java.io.UnsupportedEncodingException;\nimport java.net.URL;\nimport java.net.URLConnection;\nimport java.net.URLDecoder;\nimport java.net.URLEncoder;\nimport java.util.Vector;\n\npublic class Prueba03\n{\n public static void main(String argumentos[])\n {\n Vector<String> listaURLs = new Vector<String>();\n\n listaURLs.add("http://\xd0\xbf\xd1\x80\xd0\xb5\xd0\xb7\xd0\xb8\xd0\xb4\xd0\xb5\xd0\xbd\xd1\x82.\xd1\x80\xd1\x84/");\n listaURLs.add("http://www.\xe4\xb8\xad\xe5\x9b\xbd\xe6\x94\xbf\xe5\xba\x9c.\xe6\x94\xbf\xe5\x8a\xa1.cn");\n listaURLs.add("http://www.\xe5\x8e\x9f\xe4\xbe\x86\xe6\x88\x91\xe4\xb8\x8d\xe5\xb8\xa5.cn/");\n listaURLs.add("http://\xd9\x88\xd8\xb2\xd8\xa7\xd8\xb1\xd8\xa9-\xd8\xa7\xd9\x84\xd8\xa3\xd8\xaa\xd8\xb5\xd8\xa7\xd9\x84\xd8\xa7\xd8\xaa.\xd9\x85\xd8\xb5\xd8\xb1/");\n\n URL currentURL;\n URLConnection currentConnection;\n int currentSize;\n\n for(int i=0; i<listaURLs.size(); i++)\n {\n try\n {\n System.out.println(URLDecoder.decode(listaURLs.get(i), URLEncoder.encode(listaURLs.get(i), "UTF-8")));\n } // End of the try.\n catch(UnsupportedEncodingException uee)\n {\n uee.printStackTrace();\n } // End of the catch.\n catch(Exception e)\n {\n e.printStackTrace();\n } // End of the catch.\n\n try\n {\n currentURL = new URL(listaURLs.get(i));\n System.out.println("currentURL" + " = " + currentURL);\n\n currentConnection = currentURL.openConnection();\n System.out.println("currentConnection" + " = " + currentConnection);\n\n currentSize = currentConnection.getContentLength();\n System.out.println("currentSize" + " = " + currentSize);\n } // End of the try.\n catch(Exception e)\n {\n e.printStackTrace();\n } // End of the catch.\n } // End of the for.\n } // End of the main method.\n} // End of the Prueba02 class.\nRun Code Online (Sandbox Code Playgroud)\n