/home/caleb/ASDV-Java/Semester 2/Assignments/lab6-Exceptions_CalebFontenot/src/main/java/com/mycompany/lab6/exceptions_calebfontenot/ReadFileFromURL.java
/*
 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
 * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
 */
package com.mycompany.lab6.exceptions_calebfontenot;

import java.util.Scanner;

/**
 *
 * @author caleb
 */
public class ReadFileFromURL {
    public static void main(String[] args)
    {
        boolean continueLoop = false;
        boolean exceptionThrown = false;
        do {
        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;
            Scanner input = new Scanner(url.openStream());
            while (input.hasNext()) {
                String line = input.nextLine();
                count += line.length();
            }
            System.out.println("The file size is " + count + " characters");
            exceptionThrown = false;
        } catch (java.net.MalformedURLException ex) {
            System.out.println("Invalid URL");
            exceptionThrown = true;
        } catch (java.io.IOException ex) {
            System.out.println("IO Errors");
        }
        if (exceptionThrown) {
            continueLoop = true;
        } else {
            continueLoop = false;
        }
        } while (continueLoop);
    }
}