是否有一种方法可以从URL中构造一个FTPClient实例,例如ftp://user:pass@foo.bar:2121/path,类似于JDK中的FtpURLConnection

最佳答案

如果您的问题是解析,请使用下面的代码进行解析,然后仅创建包装器类。


导入java.net。导入java.io .;

公共类ParseURL {
公共静态void main(String [] 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
查询=名称=网络
filename = /docs/books/tutorial/index.html?name=networking
参考=下载

08-25 04:19