Solved

Using a RandomAccessFile from an applet

Posted on 1997-08-21
5
275 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
[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
  • 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

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

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
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…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
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

739 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