Solved

Using a RandomAccessFile from an applet

Posted on 1997-08-21
5
255 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

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 91
nextBoolean(double p) for Random class 3 40
oracle 11g 23 84
login form jsp example 2 25
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…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…

778 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