自己写的解析FTP地址下协议,用户名,密码,路径的代码。。。体力活

/**
 * <project>hansci_cms</project>
 * <package>com.hansci.cms.webservice</package>
 * <class>TestFTPString.java</class>
 * @time:2013-5-14 下午5:44:24
 *
 */
package com.hansci.cms.webservice;

/**
 * @author Administrator
 *
 */
public class TestFTPString {
    public static void main(String[] args) {
    	String hFTPPath = "ftp://cms:vtpicms@172.25.39.4/syncdir/remote/CCTV/response/CCTV_SOAP_RESULT_CCTV_SOAP_MSG_201305131454466493664.xml";
    	parseUrl(hFTPPath);
    	
    }
    
    public static void parseUrl(String value){ 
    	  String val;
    	  //获得协议
    	  val = value.substring(0,value.indexOf("/")-1);
    	  System.out.println("Protocal: " +val);
    	  int startIndex = value.indexOf("/")+2;
    	  int endIndex = value.indexOf(":",startIndex);
    	  
    	  //获得用户名
    	  val = value.substring(startIndex,endIndex);
    	  System.out.println("User: " +val);
    	  
    	  //获得密码
    	  startIndex = endIndex+1;
    	  endIndex = value.indexOf("/",startIndex);
    	  val = value.substring(startIndex,endIndex);
    	  val = value.substring(startIndex,value.indexOf("@"));
    	  System.out.println("Password: " +val);
    	  
    	  //默认端口号
    	  int port=21;
    	  System.out.println("Port: " +21);
    	  
    	  //获得url
    	  val = value.substring(value.indexOf("@")+1,value.length());
    	  val = val.substring(0, val.indexOf("/"));
    	  System.out.println("Url: " +val);
    	  
    	  //获得path
    	  val = value.substring(value.indexOf("@")+1,value.length());
    	  val = val.substring(val.indexOf("/")+1,val.length());
    	  System.out.println("Path: " +val);

   }
}

输出:


Protocal: ftp
User: cms
Password: vtpicms
Port: 21
Url: 172.25.39.4
Path: syncdir/remote/CCTV/response/CCTV_SOAP_RESULT_CCTV_SOAP_MSG_201305131454466493664.xml


上一篇:自动检查Tomcat等服务状态


下一篇:[译]Innodb 性能优化基础