Vikhyath_11

5

Jul 28th, 2024
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1.  
  2. package url;
  3. import java.util.*;
  4. import java.net.URL;
  5.  
  6. public class Url {
  7.  
  8. public static void main(String[] args) {
  9. try{
  10. URL u = new URL("https://www.example.com/path/to/file.html?key=value#fragment");
  11. System.out.println("Protocol : "+u.getProtocol());
  12. System.out.println("Port : "+u.getPort());
  13. System.out.println("Path : "+u.getPath());
  14. System.out.println("Host : "+u.getHost());
  15. System.out.println("Query : "+u.getQuery());
  16. System.out.println("Fragmnet : "+u.getRef());
  17. }
  18. catch(Exception e){
  19. System.out.println("Error "+ e.getMessage());
  20. }
  21. }
  22.  
  23. }
  24.  
Advertisement
Add Comment
Please, Sign In to add comment