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

x
?
Solved

Using a RandomAccessFile from an applet

Posted on 1997-08-21
5
Medium Priority
?
291 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

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

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

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
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 learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses

876 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