2011-02-09 68 views

回答

1

如果你的問題是解析,然後使用下面的代碼來解析,然後就創建一個包裝類沒有直接的構造函數...

import java.net。 ; import java.io.;

公共類的parseURL {
公共靜態無效的主要(字串[] args)拋出異常{
URL aURL =新的URL( 「http://java.sun.com:80/docs/books/tutorial」
+「/index.html?name=networking#DOWNLOADING」); System.out.println(「protocol =」+ aURL.getProtocol());
System.out.println(「authority =」+
aURL.getAuthority()); System.out.println(「host =」+ aURL.getHost()); System.out.println(「port =」+ aURL.getPort()); System.out.println(「path =」+ aURL.getPath()); System.out.println(「query =」+ aURL.getQuery()); System.out.println(「filename =」+ aURL.getFile()); System.out.println(「ref =」+ aURL.getRef());
}}

下面是由程序顯示的輸出:
協議HTTP =
權威= java.sun.com:80
主機= java.sun.com
端口= 80
路徑= /docs/books/tutorial/index.html
查詢= NAME =網絡
名= /docs/books/tutorial/index.html?name=networking
REF =正在下載

0

沒有可用於它, 您可以使用的東西

FTPClient f = new FTPClient(); 
    f.connect(server); 
    f.login(username, password); 
+0

是的,但這涉及到手動解析用戶名,密碼,端口,主機和路徑。我希望避免必須這樣做。 – hertzsprung 2011-02-09 11:28:07

+0

是的,我能理解。 :),但是你可以很容易地解析它 – 2011-02-09 11:29:06