• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Applet: attempts to access file from its originating server

 
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...
 
Saloon Keeper
Posts: 22108
151
Android Eclipse IDE Tomcat Server Redhat Java 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.
 
Your buns are mine! But you can have this tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic