尝试从 URL 读取文件时 url.openStream() 方法出错

Error with url.openStream() method when trying to read file from URL

正在尝试使用 URL class 和 url.openStream().[=15= 从 URL 读取文件]

代码:

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.
                }

我收到一条错误消息:DocFlavor.URL.

的 openStream 方法未定义

我试过的:

IDE 建议更改我所做的演员表 whihc 结果:

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

还是一样error.I也试过把Object改成URL:

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

请多多指教,谢谢!

添加了 import java.net.URL 并删除了所有其他 .net and URL imports