Solved

Using a RandomAccessFile from an applet

Posted on 1997-08-21
5
271 Views
Last Modified: 2008-03-06
I'm having a problem with opening a file as a RandomAccessFile from an online applet.  It works ok in the local version.  I get a #Security Exception:checkread: read of myfilename not permitted    when I try to use "rw" mode.
Any help?
0
Comment
Question by:glow060197
  • 2
  • 2
5 Comments
 
LVL 4

Expert Comment

by:russgold
ID: 1225485
The default security model for applets running in browsers currently does not permit *any* access to the desktop environment, including file access.

This restriction is relaxed for "trusted" applets, which are supported by HotJava only, but will be supported in future versions of Navigator and IE.  See several Previously Answere Questions in this section as well as documentation on the Javasoft website for direction on signing applets so that they can be trusted.

A future version of the JDK will also provide a very limited amount of access to files in a specific directory.
0
 

Author Comment

by:glow060197
ID: 1225486
My goal is to read it from the same directory as the applet's
*.class files, on the server, not the client.  Sorry I wasn't
very clear.
0
 
LVL 10

Expert Comment

by:kollegov
ID: 1225487
You can't refer on-line document as a RandomAcessFile.
To access documents/files at server you should use
URLConnection methods.
You can only read from stream in this case.

below example is from sun's tutorial.
It's written as application main method, but this method
will work from applet too.


import java.net.*;
import java.io.*;

        class OpenStreamTest {
            public static void main(String[] args) {
                try {
                    URL yahoo = new URL("http://www.yahoo.com/");
                    DataInputStream dis = new DataInputStream(yahoo.openStream());
                    String inputLine;

                    while ((inputLine = dis.readLine()) != null) {
                        System.out.println(inputLine);
                    }
                    dis.close();
                } catch (MalformedURLException me) {
                    System.out.println("MalformedURLException: " + me);
                } catch (IOException ioe) {
                    System.out.println("IOException: " + ioe);
                }
            }
        }

random access not supported.
0
 

Author Comment

by:glow060197
ID: 1225488
I wish I could give partial credit, but that answer doesn't
solve my problem, only gives me some ideas.  I may try to extend one of the InputStream classes to implement DataOutput, or try
PushbackInputStream.  I guess you could keep opening and closing the same file, but that's not very elegant or efficient.
0
 
LVL 4

Accepted Solution

by:
russgold earned 70 total points
ID: 1225489
While you can read from a file in your applet's codebase directories, you cannot write to them. Use "r" mode.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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
How to get all the API from website? 11 123
ejb message driven bean mdb creation steps 2 34
Eclipse for Java EE development 2 43
IBM TS2900 (3572) Tape Autoloader Java? 12 53
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…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

685 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