Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Applet: attempts to access file from its originating server

 
Karl Beyer
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an applet that
1) reads an address from a textbox(on a user's screen)
2) matches the address against a simple .txt file on the applet's server.
I've been trying to use RandomAccessFile("address.txt"), but
I have been getting security errors...
Please answer these questions for me:
1) True/False An applet has automatic access to any file in the directory from which it orginated (ie my website's server).
2) True/False You must use a URL object to connect the applet to its server.(in order to enable data transfer to the applet).
3) How do I tell the applet where the text file is (ie do i use "http://www.mywebsite.com/addresses"..)
Any help plus hints and suggestions would be much appreciated. I
am fairly new to java...
 
Tim Holloway
Saloon Keeper
Posts: 18367
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. False. A web server isn't a file server. You can't just call open() on it, and what would you use for a drive ID, anyway?
2. No. You could always roll your own connection with sockets.
3. Because of 1, above, this isn't meaningful.
What you'd actually do is place the file in one of the folders of the web server just like it was HTML. If it's a text file, your web server will normally serve it up (unless someone's changed the default configuration to something weird). You'll be able to see this by just typing in the URL for the text file, and watching it display in your browser. That's NOT a "file", however, it's a data stream loaded FROM the copy of the file on the server, and the semantic difference is important - there are HTTP headers and other things also coming down the pipe, and, as I've said, you can'd call your local open() function to make an HTTP request.
In Java, the easiest way for an applet to retrieve the contents of a server-provided file is to create a URLConnection and open an input stream on it. What you do after that depends on what your app intends to do with the data.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic