path、url、querystring常用方法

path常用方法

1、path.join([..paths])   ---->[...path] 代表 路径片段  

使用平台特定的拼接符将路径片段连接到一起,返回一个路径(注意: 长度为0则忽略,'.'当前目录, '..' 上一级目录),如: path.join('/first', 'second/third',  'forth', '..')  ; 返回: /first/second/third

 

2、path.resovle([...path])

把一个路径从右往左处理成一个绝对路径,如果没有传参数,返回当前工作目录的绝对路径

 

3、 __dirname

取当前文件所属目录的绝对路径

 

4、 __filename

获取当前文件的绝对路径

 

 

url的常用方法

public void test() throws Exception{
//创建一个URL对象,拼接对象
URL url = new URL("http://www.baidu.com");
URL url1 = new URL(url, "/index.html?usrname=xxx#test");
System.out.println(url1);//http://www.baidu.com/index.html?usrname=xxx#test
//url的常用方法
System.out.println("URL主机名称:"+url1.getHost());//URL主机名称:www.baidu.com
System.out.println("URL协议:"+url1.getProtocol());//URL协议:http
System.out.println("URL端口:"+url1.getPort());//URL端口:-1
System.out.println("URL文件路径:"+url1.getPath());//URL文件路径:/index.html
System.out.println("URL查询字符串:"+url1.getQuery());//URL查询字符串:usrname=xxx
System.out.println("URL相对路径:"+url1.getRef());//URL相对路径:test
System.out.println("URL文件名:"+url1.getFile());//URL文件名:/index.html?usrname=xxx

}

 

 

 

querystring常用方法

1、stringify

 querystring.stringify({name:13} )
'name=13'

 

2、parse

querystring.parse('name=13')
{ name: '13'}

 

3、escape和unescape

 

querystring.escape('哈哈哈')
'%E5%93%88%E5%93%88%E5%93%88’

 

querystring.unescape('%E5%93%88%E5%93%88%E5%93%88')
'哈哈哈’

posted @ 2020-02-12 16:21  冰可乐不是雪碧  Views(414)  Comments(0Edit  收藏  举报