URL的getFile()和getPath()方法的区别

import java.net.MalformedURLException;  
import java.net.URL;  
  
  
public class dd {  
  
    /** 
     * @param args 
     */  
    public static void main(String[] args) {  
        try {  
            URL url = new URL("file://ftp.yoyodyne.com/pub/files/foobar.txt?id=123456");  
            System.out.println("url.getFile()="+url.getFile());  
            System.out.println("url.getPath()="+url.getPath());  
        } catch (MalformedURLException e) {  
            e.printStackTrace();  
        }  
    }  
}  


返回的结果:

url.getFile()=/pub/files/foobar.txt?id=123456
url.getPath()=/pub/files/foobar.txt


你可能感兴趣的:(java)