2011-02-09 25 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