• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Accessing a txt file using URL.class

 
Jon Davies
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I've written an applet which searches through a txt file, but I am having problems when running the applet through a web browser.
I now understand (thanks to Alex) that I must use the URL.class and access the txt file as a resource, but I'm not sure how I should go about this. I can set the URL as follows (I'll change the path when needed):
URL url = new URL(getCodeBase(), "C honeList.txt");
...but I'm not sure what to do next. This provides the URL for the txt file but how do I access it and can I do so as a txt file? Is it possible to still use the FileReader class?
TIA
Jon
 
Joe Ess
Bartender
Posts: 9337
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the documentation for java.net.URL says that one can use the method openStream() to get an InputStream to read the contents from. Obviously you can't use FileReader on an InputStream, but you can use InputStreamReader, which is the parent class of FileReader.
You need to move your phone list file to where the web server can get to it, and I doubt that C:\ is one of those places.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic