Solved

Using a RandomAccessFile from an applet

Posted on 1997-08-21
5
238 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
While you can read from a file in your applet's codebase directories, you cannot write to them. Use "r" mode.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now