/home/caleb/ASDV-Java/Semester 2/Assignments/lab6-Exceptions_CalebFontenot/src/main/java/com/mycompany/lab6/exceptions_calebfontenot/ReadFileFromWeb.java |
package com.mycompany.lab6.exceptions_calebfontenot;
import java.util.Scanner;
@author
public class ReadFileFromWeb {
public static void main(String[] args) {
System.out.print("Enter a URL: ");
String URLString = new Scanner(System.in).next();
try {
java.net.URL url = new java.net.URL(URLString);
int count = 0;
String text ="";
Scanner input = new Scanner(url.openStream());
while (input.hasNext()) {
String line = input.nextLine();
count += line.length();
text += line;
}
System.out.println("The file size is " + count + " characters.");
System.out.println(text);
} catch (java.net.MalformedURLException ex) {
System.out.println("Invalid URL");
}
catch (java.io.IOException ex) {
System.out.println("IO Errors!");
}
}
}