0
try {
    while ((inputLine = bufferedReader.readLine()) != null) {
    String[] words = inputLine.split("[ \n\t\r.,;:!?(){}]");

    for (int wordCounter = 0; wordCounter < words.length; wordCounter++) {
        String key = words[wordCounter].toLowerCase();
        if (key.length() > 0) {
            if (map.get(key) == null) {
                map.put(key, 1);
            }
            else {
                int value = map.get(key).intValue();
                value++;
                map.put(key, value);
            }
        }

        Set<Map.Entry<String, Integer>> entrySet = map.entrySet();

        for (Map.Entry<String, Integer> entry : entrySet) {
            System.out.println(entry.getValue() + "\t" + entry.getKey());
        }
    }
} catch (IOException error) {
    System.out.println("Invalid File"); 
}
Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360
TheDingo
  • 59
  • 6
  • You're not changing `input`. – 4castle Apr 27 '17 at 01:18
  • If you're using Java 7+, you may want to use the [syntax for catching multiple exception types in the same catch clause](http://stackoverflow.com/q/3495926/5743988). – 4castle Apr 27 '17 at 01:27

1 Answers1

2

Restructure your loop so that the user is prompted for new input inside the loop:

public static void main (String[] args) {
    Scanner scan = new Scanner(System.in);
    Scanner web = null;

    while (true) {
        try {
            String input = scan.nextLine();
            URL url = new URL(input);
            web = new Scanner(url.openStream());

            break;

        } catch (MalformedURLException e) {
            System.out.println("error occurred: " + e);

        } catch (IOException e) {
            System.out.println("error occurred: " + e);
        }
    }

    if (web != null ) {
        // do something with 'web'
    }
}
Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360