Advertisement
Guest User

Untitled

a guest
Aug 24th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. package ikinciHaftam;
  2. import java.io.IOException;
  3. import java.net.MalformedURLException;
  4. import java.net.URL;
  5. import java.util.Scanner;
  6.  
  7. public class ReadFileFromURL {
  8.  
  9. public static void main(String[] args) {
  10. // TODO Auto-generated method stub
  11. System.out.print("Enter a URL: ");
  12. Scanner inURL = new Scanner(System.in);
  13. String URLString = inURL.next();
  14. inURL.close();
  15. try{
  16. URL url = new URL(URLString);
  17. int count =0;
  18. Scanner input = new Scanner(url.openStream());
  19. System.out.println(url.openStream());
  20. while (input.hasNext()){
  21. String line = input.nextLine();
  22. count += line.length();
  23. }
  24. System.out.println("The file size is " + count + " characters");
  25. input.close();
  26. }
  27. catch(MalformedURLException ex){
  28. System.out.println("Malformed url");
  29. }
  30. catch(IOException e){
  31. System.out.println("I/O error: no such file");
  32. }
  33.  
  34. }
  35.  
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement