Zag Gol
Zag Gol

Reputation: 1076

Can't open a text file

I call function with:

Anagrams("http://www.puzzlers.org//pub//wordlists//unixdict.txt");

In the function I write:

public static void Anagrams(String path)
{
    BufferedReader br;
    try {
        br = new BufferedReader(new FileReader(path));

And I get an error:

java.io.FileNotFoundException: http:\www.puzzlers.org\pub\wordlists\unixdict.txt

But when I put the path in a browser, the browser opens the file fine.

Upvotes: 0

Views: 625

Answers (1)

keshlam
keshlam

Reputation: 8058

You're trying to read from a URI across the network, not a file on a local system. FileReader is the wrong tool. Create a URI object from that string, call openStream() against that to get the network connection to it, wrap an InputStreamReader around it, and then wrap the BufferedReader around that.

See, for example, Oracle's example in their documentation

Upvotes: 3

Related Questions