Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Access RandomAccessFile from within an Applet

Posted on 1997-04-24
1
Medium Priority
?
280 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 20 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses

885 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