Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ikinciHaftam;
- import java.io.IOException;
- import java.net.MalformedURLException;
- import java.net.URL;
- import java.util.Scanner;
- public class ReadFileFromURL {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- System.out.print("Enter a URL: ");
- Scanner inURL = new Scanner(System.in);
- String URLString = inURL.next();
- inURL.close();
- try{
- URL url = new URL(URLString);
- int count =0;
- Scanner input = new Scanner(url.openStream());
- System.out.println(url.openStream());
- while (input.hasNext()){
- String line = input.nextLine();
- count += line.length();
- }
- System.out.println("The file size is " + count + " characters");
- input.close();
- }
- catch(MalformedURLException ex){
- System.out.println("Malformed url");
- }
- catch(IOException e){
- System.out.println("I/O error: no such file");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement