Java爬虫的相对路径转绝对路径

mac2022-06-30  90

网上看到的,摘录如下:

@SuppressWarnings("finally") public static String getAbsoluteURL(String baseURI, String relativePath){ String abURL=null; try { URI base=new URI(baseURI);//基本网页URI URI abs=base.resolve(relativePath);//解析于上述网页的相对URL,得到绝对URI URL absURL=abs.toURL();//转成URL System.out.println(absURL); abURL = absURL.toString(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (URISyntaxException e) { e.printStackTrace(); } finally{ return abURL; } }

转载于:https://www.cnblogs.com/kinglearnjava/p/4883291.html

相关资源:JAVA上百实例源码以及开源项目
最新回复(0)