Solved

Access RandomAccessFile from within an Applet

Posted on 1997-04-24
1
241 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
topping1 challenge 7 72
how do i compare an object based on two fields 6 48
eclipse argument 14 53
Java DateChooser? 3 29
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
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 will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

914 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now