0

Trying to read a file from URL using URL class and url.openStream().

The code:

try {
                   URL url = new URL("http://www.puzzlers.org/pub/wordlists/pocket.txt");
                   Scanner s = new Scanner(url.openStream());
                   // read from your scanner
                }
                catch(IOException ex) {
                   // there was some connection problem, or the file did not exist on the server,
                   // or your URL was not in the right format.
                   // think about what to do now, and put it here.
                   ex.printStackTrace(); // for now, simply output it.
                }

I get an error saying: The method openStream iusundefined for the DocFlavor.URL.

What I tried:

The IDE suggest to change cast which I did whihc results in:

URL url = new URL("http://www.puzzlers.org/pub/wordlists/pocket.txt");
                   Scanner s = new Scanner(((Object) url).openStream());
                   // read from your scanner

Still the same error.I also have tried changing Object to URL:

URL url = new URL("http://www.puzzlers.org/pub/wordlists/pocket.txt");
                   Scanner s = new Scanner(((URL) url).openStream());
                   // read from your scanner

Please assitst and thank you!

Franco
  • 441
  • 3
  • 18

1 Answers1

0

Added import java.net.URL and removed all other .net and URL imports

Franco
  • 441
  • 3
  • 18