Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Access RandomAccessFile from within an Applet

Posted on 1997-04-24
1
256 Views
Last Modified: 2012-06-21
If I want to write an Applet which read and display a file, is it true that
I always need to do via

    URL thisURL = new(getCodeBase(), filename);
    InputStream thisIS = thisURL.openStream();

no matter where the file is? Then what can I do if I want to open a
RandomAccessFile? Is there a more direct method to access a local file within
the same directory as the Applet code?

Many thanx in advance
0
Comment
Question by:gabbana
1 Comment
 
LVL 6

Accepted Solution

by:
jpk041897 earned 10 total points
ID: 1219824
Regarding the first part of your question.

Actualy, there are several other options for addressing.

You can use getDocumentBase(), instead of getCodeBase() to read a file that exists on the same directory as the HTML file that loads the applet while getCodeBase() uses the directory where the applet was contained.

You can also use: new URL("http://www.server.com/dir/file");

(or "file:///path/file" if both applet and file are running on the server)

Problem with this last  method is that you can only access file that are based on the web host root directory not the systems if running over the web.

Regarding RandomAccessFile:

The sochets support of Java does not support full duplex communication on a single channel, it requires one stream each for input and output, therfore you cannot associate a RandomAccesFile class to a TCP or UDP stream (Random access requires both input and output on the same stream)

The alternative is to let a server app. access the file for you and transmit the data obtained to the applet. To do this you would need to set up a listener thred in the server (similar to what chat apps do) and process random access requests (basicaly read and write operations).

You would also have to set up a simple protocol (say ::Get::RecNum:: , ::Put::RecNum::String, ::Append::String, etc) and have the listener parse for thiese tokens in its input stram in order to invoke the appropaiate file method, build the response string and transmit the data.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
more than one jdk and one jre 1 50
Detect Closed Loops (circles, figure-8s, etc) in PNG Images 6 56
how to debug htl and js pages 8 39
Is there a simpler dropbox system? 10 34
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This video teaches viewers about errors in exception handling.

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question