Solved

Access RandomAccessFile from within an Applet

Posted on 1997-04-24
1
266 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
[X]
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
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Android development question 2 108
JavaFX TableView not displaying correctly 3 160
What's wrong with this code? 4 46
Setup GlassFish 4 55
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
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

734 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