Applets : reading other files (AccessControlException workaround)

i hava an applet which should read some files located in a subdirectory of the applet root and which are handled as RandomAccessFile, but applets don't have permissions to read these files.
is there a workaround ?

ONE SOLUTION IS THAT YOU SIGN THE APPLET
SECOND USE THE URL CLASS TO ACCESS THE FILE

Similar Messages

  • How do I make an Applet read a file on my web host?

    How do I make an Applet read a file on my web host?
    I am wanting to put a file on my web host that has usernames and user details and other stuff on it...
    I was wondering whether anyone knows how to make the Applet open a file on my webserver, check if the username exists, if not add to the file the username and details?
    thanks

    URL myURL = new URL(getDocumentBase(), filename);
    InputStream myInputStream = myURL.openStream();
    DataInputStream dis = new DataInputStream(myInputStream);
    String oneLine = dis.readLine();
    Use output stream for writing..
    hope this works !!!

  • Applet read/write files

    Hi,
    I have a problem to use getCodeBase to get the URL. Actually, I am pretty confused on running the applet in our intranet.
    Let me explain my problem here, I have mapped a network drive(G:\personA) in my machine and my applet and all the files are in G:\personA\classes. In my coding, I have tried to specify my files paths such as G:\personA\classes\index.txt and I can run the applet without any problem either with Eclipse or from a web site http://personA//report.html. But the other members in this company cannot run this applet thro' this web site( http://personA//report.html). The problem is "No class found", can't find the path G:\personA\classes\index.txt.
    So I decided to change my code by reading/writing files thro URL i,e : http://personA/classes, but when I run my applet, I got the following exception :
    ava.lang.NullPointerException
         at java.applet.Applet.getCodeBase(Applet.java:136)
         at web.MyChart.readAndPrintData(MyChart.java:336)
         at web.MyChart<init>(MyChart.java:113)
         at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
         at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
         at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
         at java.lang.reflect.Constructor.newInstance(Constructor.java:274)
         at java.lang.Class.newInstance0(Class.java:308)
         at java.lang.Class.newInstance(Class.java:261)
         at sun.applet.AppletPanel.createApplet(AppletPanel.java:617)
         at sun.applet.AppletPanel.runLoader(AppletPanel.java:546)
         at sun.applet.AppletPanel.run(AppletPanel.java:298)
         at java.lang.Thread.run(Thread.java:534)
    does anybody knows how to solve this problem?? Please...
    Thanks,
    Tiffany

    I think a trace would help, guessing is fun but won't solve your problem:
    To turn the full trace on (windows) you can start the java console, to be found here:
    C:\Program Files\Java\j2re1.4...\bin\jpicpl32.exe
    In the advanced tab you can fill in something for runtime parameters fill in this:
    -Djavaplugin.trace=true -Djavaplugin.trace.option=basic|net|security|ext|liveconnect
    if you cannot start the java console check here:
    C:\Documents and Settings\userName\Application Data\Sun\Java\Deployment\deployment.properties
    I think for linux this is somewhere in youruserdir/java (hidden directory)
    add or change the following line:
    javaplugin.jre.params=-Djavaplugin.trace\=true -Djavaplugin.trace.option\=basic|net|security|ext|liveconnect
    for 1.5:
    deployment.javapi.jre.1.5.0.args=-Djavaplugin.trace\=true -Djavaplugin.trace.option\=basic|net|security|ext|liveconnect
    The trace is here:
    C:\Documents and Settings\your user\Application Data\Sun\Java\Deployment\log\plugin...log
    I think for linux this is somewhere in youruserdir/java (hidden directory)

  • Reading other files

    here is my program. it compiles fine, but for some reason, it is unable to read the file, numbers.txt. i made sure they are in the same directory, and it still doesnt work. it may have something to do with me using dr. java, but im not sure. here is the error message.
    java.io.FileNotFoundException: numbers.txt (The system cannot find the file specified)
    import java.io.*;
    public class bubbleSort4{
      public static void main (String []args) throws IOException{
        BufferedReader input = new BufferedReader (new FileReader ("numbers.txt"));
            int array1 [] = new int [16];
            for (int blah = 0 ; blah <= 15 ; blah++){
                array1 [blah] = Integer.parseInt (input.readLine ());
            } //end of for
            input.close ();
            bubbleSort4 (array1);
            System.out.println ("The sorted numbers are: ");
            for (int dd = 0 ; dd < array1.length ; dd++){
                System.out.println (array1 [dd]);
            } //end of for
            System.out.println ("The median is " + array1 [array1.length / 2]);
        } //end of main
    public static void bubbleSort4(int[] array1) throws IOException{
      int newLowest = 0;            // index of first comparison
        int newHighest = array1.length-1;  // index of last comparison
        while (newLowest < newHighest) {
            int highest = newHighest;
            int lowest  = newLowest;
            newLowest = array1.length;    // start higher than any legal index
            for (int i=lowest; i<highest; i++) {
                if (array1[i] > array1[i+1]) {
                   // exchange elements
                   int temp = array1; array1[i] = array1[i+1]; array1[i+1] = temp;
    if (i<newLowest) {
    newLowest = i-1;
    if (newLowest < 0) {
    newLowest = 0;
    }//end of if
    } else if (i>newHighest) {
    newHighest = i+1;
    }//end of else if
    }//end of if
    }//end of for
    }//end of while
    }//end method bubbleSort4
    }//end of class

    This...
    java.io.FileNotFoundException: numbers.txt (The
    system cannot find the file specified)...combined with this...
    (new FileReader ("numbers.txt"));...means there's no file (or no file that your program can read) called numbers.txt in the current directory. "The current directory" is whatever directory you were in when you invoked java bubbleSort4, or whatever directory your IDE considers current if you're running your code that way. You can see the current dir with System.getProperty("user.dir").

  • How to read a file ?

    Hi,
    Thank every one for your good suggestions! I solve my questions with your help.
    I hava other question:
    you know that I run my applet program online, but I want to read a file
    (.txt) which is saved on web servier side. the path name of the file is URL looks like "www.uottawa.ca/~jzhan037/file.txt". How to get this file pathname? because the path name of the file can not be set to URL, RIHGT? so please give me some suggestions! Thanks!

    You can read your file in the server side by:
    URL url = new URL("http://www.uottawa.ca/~jzhan037/file.txt");
    URLConnection connection = url.openConnection();                         
    InputStream iptS = connection.getInputStream();
    But if your file is in the different url with your applet file, you will get exception because security reason. In that case, you have to sign your applet.

  • AccessControlException in signed applet for simply reading local file

    I have a simple applet that reads specified local image files and uploads them to our server. On both Mac OS X and WinXP (firefox and IE7), I get the following error. I signed the applet using an InstantSSL code signing certificate (not so easy getting this to work, but I'm pretty confident I did it correctly).
    java.security.AccessControlException: access denied (java.io.FilePermission /Users/scott/Documents/photos/Ken_and_Scott.jpg read)
         at java.security.AccessControlContext.checkPermission(AccessControlContext.java:264)
         at java.security.AccessController.checkPermission(AccessController.java:427)
         at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
         at java.lang.SecurityManager.checkRead(SecurityManager.java:871)
         at java.io.File.length(File.java:813)
         at org.apache.http.entity.mime.content.FileBody.getContentLength(FileBody.java:89)So just on getting the file length, it's throwing this exception. Interestingly, this file passed both file.exists() and file.canRead() checks within the applet (in windows the path is a bit different of course but also passes both those checks). Also, that file has no read restrictions and I can load it in a browser no problem.
    I assume I'm missing a step in the applet code signing process, maybe a step that says I'm allowed to read local files?

    I figured out my issue, the apache HttpClient library needed to be signed too apparently.

  • Reading All Files inside folder codeBase, Applet!

    I have an applet, placed in a Jar file.. everything is ok,,
    I have a resource folder outside the Jar, which has some files.
    how can I read what is inside the resource folder, which is located outisde the Jar, without having their addresses before hand!!
    in short, I would like the applet to open the resource folder, get an array of all files in the folder, and then reads them.
    I tried encapsulating the getCodeBase().toURI() with a File Object.
    But when I call the file.list() it throws an AccessControlException
    thank you.

    Here is a simple example of using ftp to obtain file list using Jakarta common net package.
    // ftp - related imports
    import org.apache.commons.net.ftp.FTPClient;
    import org.apache.commons.net.ftp.FTPReply;
    // main method
              FTPClient ftpClient = null;
              try {
                   ftpClient = new FTPClient();
                   ftpClient.connect("REMOTE_HOST", "remote port, use 21 in common case");
                   System.out.print(ftpClient.getReplyString());
                   int reply = ftpClient.getReplyCode();
                   if(!FTPReply.isPositiveCompletion(reply)) {
              ftpClient.disconnect();
              System.err.println("FTP server refused connection.");
              System.exit(1);
                   boolean isLoggedIn = ftpClient.login("your login", "your pass");
                   ftpClient.changeWorkingDirectory("/your remote dir/");
                   String[] fNames = ftpClient.listNames();
                   for (int i = 0; i < fNames.length; i++) {
                        System.out.println(fNames);
                   ftpClient.logout();
              } catch (IOException e) {
                   e.printStackTrace();
              } finally {
                   if(ftpClient.isConnected()) {
                        try {
                             ftpClient.disconnect();
                        } catch(IOException ioe) {
                             ioe.printStackTrace();
    System.exit(0);

  • Applet reading and loading Files

    Gud Day!!!
    Id created a An applet program loading a textFile
    from my C:\ directory and when i test it, if the file exists
    it gives me a
    "security.AccessControlException: access denied(Java.io.FilePermission read)" error
    my code is
    name = new File("C:\hello.txt");
    if ( name.exists() )
    /*some code
    here */
    thanks! For some future help!!!

    hum
    you should read what security restrictions applets have.
    You can make that applet work by signing your applet and then giving it rights.

  • Reading from the Applet's JAR file.

    Is it possible to read a file stored in the jar file that the (unsigned) applet is being executed in? I have a line that goes like (in is just an InputStream):
    in = getClass().getResource( "/exercise.xml" ).openStream();
    and then, in another class, i do (bulider is an instance of javax.xml.parsers.DocumentBuilder, created from the DocumentBuilderFactory class):
    doc = builder.parse( in );
    but this always results in a security exception (works fine from the applet viewer). I tried specifying the full path to the .jar file as the codebase, but got the same results. I have not tested this from an actual web server, i am only opening the .html file directly in IE.
    Due to the nature of the application, it is not possible to host the file seperately on a webserver.
    It seems to me that there is no reason an applet shouldnt be allowed to load a file from the .jar it is executing in, could this simply be a problem of the file being local, and thus linked to from a file:// tag?
    Thanks for any help.
    Thomas Stephens

    Hi Guys
    I have figured out this problem. It's got to do with classloader.
    Applet uses a separate classloader. So using the static getSystemResource(),
    we never get contents from applet jar files. The following will work nicely.
    It is noted that you must loacate the applet classloader as in the first line
    and use the non-static method getResource();
    ObjectInJar obj = new ObjectInJar(); // create an object with a class in the jar file.
    ClassLoader cl = obj.getClass().getClassLoader();
    InputStream stream = cl.getResource("your_filepath_in_jar").openStream();
    Cheers.

  • URGETN HELP NEEDED! JAVA APPLET READING FILE

    Hi everyone
    I need to hand in this assignment today
    Im trying to read from a file and read it onto the screen, my code keeps showing up an error
    'missing method body, or declare abstract'
    This is coming up for the
    public statuc void main(String[] args);
    and the
    public void init();
    Here is my code:
    import java.io.*;
    import java.awt.*;
    import java.applet.*;
    public class Empty_3 extends Applet {
    TextArea ta = new TextArea();
    public static void main(String[] args);
    public void init();
    setLayout(new BorderLayout());
    add(ta, BorderLayout.CENTER);
    try {
    InputStream in =
    getClass().getResourceAsStream("test1.txt");
    InputStreamReader isr =
    new InputStreamReader(in);
    BufferedReader br =
    new BufferedReader(isr);
    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    String line;
    while ((line = br.readLine()) != null) {
    pw.println(line);
    ta.setText(sw.toString());
    } catch (IOException io) {
    ta.setText("Ooops");
    Can anyone help me please?
    Is this the best way of doing this? Once i read the file i want to perform a frequency analysis on the words so if there is a better method for this then please let me know!
    Thankyou
    Matt

    Whether it is urgent or not, does not interest us. It might be urgent for you but for nobody else.
    Writing all-capitals is considered shouting and rude.
    // Use code tags for source.

  • WebLogic writes to a text file and an applet reads the text file

    Hi there,
    I need some help here!
    I have an applet that needs to read from a text file:
    final URL prtDataURL = new URL("http://" + getCodeBase().getHost() + ":" + getCodeBase().getPort() + "/ESTC/lib/prtDataFile.txt");
                final URLConnection urlConn = prtDataURL.openConnection();
                urlConn.setUseCaches(false);
                urlConn.setDoInput(true);
                urlConn.setDoOutput(false);
                final InputStreamReader is = new InputStreamReader(urlConn.getInputStream());
                final BufferedReader in = new BufferedReader(is);
                String inputLine;
                while ((inputLine = in.readLine()) != null){
                    String[] tmp = inputLine.split("§");
                    this.dateTime = tmp[0];
                    this.quanTot = Integer.parseInt(tmp[1]);
                    this.quanSco = Integer.parseInt(tmp[2]);
                    this.quanSef = Integer.parseInt(tmp[3]);
                    this.valTot = Double.parseDouble(tmp[4]);
                    this.valSco = Double.parseDouble(tmp[5]);
                    this.valSef = Double.parseDouble(tmp[6]);
                in.close();
                is.close();and this is ok.
    Now I have the web server (WebLogic) that must write, at regular time intervals, to that file (prtDataFile.txt). The web application writes to the file (which belongs to the application).
    I've tried open the file with the File object but since the war file is unexploded I can't get the real path!
    I've tried open an url connection,
    final URL url = new URL("http://10.191.33.249:16801/ESTC/lib/prtDataFile.txt");
    final URLConnection connection = url.openConnection();
    connection.setDoOutput(true);
    connection.setUseCaches(false);
    connection.setDoInput(false);
    OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream());
    out.write(currentDate + "§" + quantTot + "§" + quantSco + "§" + quantSef + "§" + valTot + "§" + valSco + "§" + valSef);;
    out.flush();
    out.close();which seems a little stupid since I'm opening an URLConnection to the same place where the application is. Anyway it doesn't work, i.e., it doesn't write to the file but it doesn't gives me any errors or exceptions.
    Is there another way to get this two pieces communicating?
    Thanks in advance

    I have almost the exact same problem, and I am in the same situation as you are with respects to the language.
    I am simply trying to create a file and output some garbage to it but my applet always spits back a security violation. I've tried eliminating the restrictions on the applet runner I use but I still get the error.
    My method:
    debug = new Label() ;
    debug.setLocation( 20, 20 ) ;
    debug.setSize( 500, 15 ) ;
    add( debug ) ;
    // output
    try
         OutputStream file = new FileOutputStream( new File( "" + getCodeBase() + "output.txt" ) ) ;
         byte[] buffer = { 1, 2, 3, 4, 5 } ;
         file.write( buffer ) ;
         file.close() ;
    } catch( Exception e )
         debug.setText( e.toString() ) ;
         Can anyone tell why this isnt working?

  • Applet can't read local file on web server, security issue!

    There is any way to read/write files of web server through the applet except the Signed Applet.
    If any idea the reply me soon.
    Thanks in advance

    Applets are downloaded from web servers and execute on the client machine.
    Therefore they have no access to the web server file system, signed or not.
    They could have access to the client file system (the machine where they run),
    but for security reasons only signed applets have this privilege.
    So to answer your question, you sign if you want to access client files.
    To access web server files, you don't need to sign the applet, but you need
    to provide some method of accessing files remotely, for instance:
    - Files published for the web can be read using HTTP
    - Files can be read or writen with the help of an FTP server on the same machine as the web server
    - A servlet running on the HTTP server can collaborate with your applet to exchange files

  • Applet reading files in in web server eg geocities

    hi ,
    i have an applet that reads files i have created in a web server. when i try to run the applet in , internet explorer i get an error message
    java.io.FileNotFoundException: nic.txt (The system cannot find the file specified)
    does anyone have any solution to this problem. do i need a policy file and if i do where do i put it.

    Applets work on the clients computer, not the server. Your applet is >trying to read nic.txt from your computer. Can't be done easily, you'd >need your own serverprogram to do the reading and pass the data to the >client... let me clarify afew points
    the applet is on a webserver eg. geocities.
    the file is also on the same directory as the applet .class file.
    so everything is on the web server,.

  • Applets reading files in their own jar file

    I know there is no way to get my applet to read a file on the hard disk. But
    could I read one that I include in with the .jar file that I create for my applet?
    What about using a Resource type of file? Is this possible?
    Thanks

    Here's a little code stub I used to read a properties file from rt.jar    Properties p = new Properties();
        InputStream is = ClassLoader.getSystemClassLoader().getResourceAsStream
         ("java/awt/resources/awt.properties");
        if (is == null) System.out.println("NULL");
        else try { p.load(is); }
        catch (Exception exc) { System.out.println("Exception"); }
        p.list(System.out);You should be able to substitute your path & properties file

  • Finding other files in same ftp to use in applet

    I have created a signed applet that can access, write, and delete files within the same folder as the jar file containing the class (signed applets require jar files to hold the class). On my computer I use
    String dir = getCodeBase().getPath(); to locate whatever directory the jar file may be in, which works. However, when I put everything (jar, files, signed html applet, etc) on my ftp (same setup as on my computer) and try to run the applet online, it cannot find the files. How do I solve this?

    I see... I am not very familiar with client/server interactions. I have made a very simple text messaging before. However, it only allowed one connection a time. Is it possible to create a server that can receive any number of connections to send data needed for the client's applet and receive specific commands to modify certain data on the server side?
    In a very basic example:
    A server keeps a Serializable file containing a list of names. Any number of client can visit the applet's web page, which automatically makes the connection to the server. The client is then provided with the list of names and the options (JButtons with JTextFields) to add a name, modify a name, or delete a name which changes the file's information.
    If such is possible, could you point me to a tutorial that mainly deals about creating this type of server.

Maybe you are looking for

  • Document error for BI 7.0

    environment: BI 7.0 SP9 & EP 7.0 SP9 We managed to run BI report in EP, but error appears when try to create documents on master data via right click the charactersitic value in the report, following is our preliminary setting: - "Document links for

  • Bapi re: CO11N BAPI_PRODORDCONF_GET_TT_PROP & BAPI_PRODORDCONF_CREATE_TT

    Hi,   I have a little problem with the bapi's   BAPI_PRODORDCONF_CREATE_TT and BAPI_PRODORDCONF_GET_TT_PROP 1.  in abap i call BAPI_PRODORDCONF_GET_TT_PROP first , the proposed goodsmovement is not the same as the default on co11n, it does not includ

  • What is l_s_range in the Exit?

    Hi, I am new to BW reporting.  I saw the coding in user exit 'EXIT_SAPLRRS0_001' L_S_RANGE-LOW = '06', something like that.  My question is, is this 'L_S_RANGE' a structure? how do I know what fields are there? I tried to see this in SE84 under struc

  • Help positioning objects

    In my index file, before I bring it into Edge,  I have all objects centered on the page this way: #parallax-bg1 {           z-index: 1;           position: fixed;           left: 58.5%;           top: 0;           width: 1130px;           margin-left

  • Can anyone help me to find the page list for my site?

    I cannot seem to find the icon which will lead me to the page list for my site. I need it to retrieve a lost page