0

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.

Boann
  • 48,794
  • 16
  • 117
  • 146
Zag Gol
  • 1,038
  • 1
  • 18
  • 43
  • I'm pretty sure you need to be using an input stream reader rather than a file reader. Consult [this](http://docs.oracle.com/javase/tutorial/networking/urls/readingURL.html). – Compass Oct 05 '14 at 01:11
  • Just a random guess. but you use "//" in your call to the function. The escape character is "\\" try that. – Stephen Buttolph Oct 05 '14 at 01:12
  • i tried using input stream reader, and "\\" as eascape characters, but stillget the same error. – Zag Gol Oct 05 '14 at 01:19
  • possible duplicate of [Java fileinputstream using with url](http://stackoverflow.com/questions/5528388/java-fileinputstream-using-with-url) – Joe Oct 05 '14 at 02:18
  • possible duplicate of [How to read a text file directly from Internet using Java?](http://stackoverflow.com/questions/6259339/how-to-read-a-text-file-directly-from-internet-using-java) – Stephen Buttolph Oct 05 '14 at 02:26

1 Answers1

3

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

keshlam
  • 7,931
  • 2
  • 19
  • 33
  • Or, easier, OP should just Ctrl+S the file to disk. – Boann Oct 05 '14 at 02:20
  • @Boann: They'd then have to change their code to read from where they saved it on disk. And they'd have to worry about whether the saved copy was current. That may be a perfectly reasonable approach, but it didn't seem to be the question they were asking. – keshlam Oct 05 '14 at 02:22
  • ‎@keshlam Yes, but there is always code to change. And there are always things to worry about. If they read it from online, they have to worry about whether the URL stays current, and whether a network connection is available, and the traffic usage, and whether the site will let them scrape that file every time their program runs, and any privacy concerns of it all. – Boann Oct 05 '14 at 02:27
  • Thanks for the input, but we agree that we disagree. – keshlam Oct 05 '14 at 02:33