APPLETS and ACESSING FILES

The following is my code. I want to be able to search the flat text data file for inputed query. I have managed to do it one way with out applet wise, but I had to use URL. I creates the URL but get stuck on the BufferReader more specifically the openStream method I think. Now the file I am trying to access is on the server which is behind a firewall.
any good suggestions or even new aproaches are welcomed
import java.awt.*;
import java.applet.*;
import java.lang.*;
import java.lang.Object;
import java.io.*;
import java.net.URL;
public class Goin extends Applet {
     Font f = new Font("Georgia",Font.BOLD,36);
     public void init() {
               try{
                         System.out.println("we are in");
                         URL yahoo = new URL("http://www.nj.gov/military/test/testme.txt");
                         System.out.println("assigned url");
                    BufferedReader in = new BufferedReader(new InputStreamReader(yahoo.openStream()));
                    System.out.println("created buffer");
                    String line = in.readLine();
                    System.out.println("we read one line");
                    while ( line != null )
                         System.out.println("we are in for a while");
                         line = in.readLine();
                         int index = line.indexOf("t");
                         if ( index != -1)
                              System.out.println("we are in if");
                              System.out.println(line);
                              System.out.println("we are out if");
                         System.out.println("we are out for a while");
                    in.close();      
                    }catch (IOException e)
                    {System.out.println("Error -- " + e.toString());}     
                    System.out.println("we are finishing");}

they do but you have to use what i have except you may have to specify other things. Actually I just found out that the url I used is down so that may be the problem.

Similar Messages

  • Applets and accessing files confusion

    Hi
    I am confused about applets and their abilty to access files.
    I know that applets cannot access files on a users hard drive until given pemission but if i design an applet that needs access to files on the server where it is running will it be able to read and write those files in the same location as the applet without the need to set permissions?
    Any feedback would be great
    Neil

    The applet is very much able to read files from the server. This is easiest done by creating a URL and opening a stream to it:
    URL url = new URL(getCodeBase(), "file.dat");
    InputStream in = url.openStream();
    // read from the stream...
    in.close();
    Saving files to the server is also possible without setting permissions but it's a bit harder. In short, you need some sort of server that accepts a connection and saves what you send it to disk. The server can be eg. a servlet, a database or a FTP server.

  • Infobus applet and temporary files

    Hi,
    I have made an infobus applet and deploy it with the OAS407.
    Now I have seen, that each time I load the applet from the
    OAS407 the applet create 15 files in my temp-folder with the
    prefix jar_cache (for example: jar_cache40989.tmp).
    There is no problem with creating but there is a problem with
    deleting because there is no mechanism for automatic deleting.
    So I have to delete these files manually but I think that this
    is unuseable for end-user.
    Does anybody know how to bypass this problem ?
    Thanks.
    Nils
    null

    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by Nils Buering ([email protected]):
    I ran into the same problem when I built an applet that uses DAC and runs the app module in the downloaded applet. The Java plugin 1.2.2 is creating these files in TEMP and these files are equal in size to the support jar and zip files downloaded to the browser. You can easily verify this by comparing file sizes (use the Properties facility when you right click a Windows file sname to see its exact size in bytes). The plugin does not delete these files when you exit the browser and thus re-creates them every time you restart the browser and access the applet from the web server potentially filling the user's disk.
    SUN has fixed this problem with the 1.3 plugin. Ater downloading and installing the 1.3 plugin, you must edit the applet's HTML file to add two new PARAM options: "cache_option" and "cache_archive". See http://java.sun.com/j2se/1.3/docs/guide/misc/appletcaching.html for instructions (a document titled "Applet caching in Java Plug-in") on doing this. This basically tells the plugin to use its own caching, instead of the browser's and doing this, the jar files created in the user's TEMP directory are deleted when you kill the browser.
    However, since Jdeveloper is not certified with Java 2 v1.3, I ran into problems with code that works under the 1.2.2 plugin. The applet no longer runs once its been downloaded: I get a permissions error in jbo.logging.show and jbo.logging.trace; to wit: (java.lang.ExceptionInInitializerError: java.security.AccessControlException: access denied (java.sql.SQLPermission setLog). So switching to the 1.3 plugin will fix the buildup of jar files in TEMP problem; but your applets may no longer work! Best to wait until Jdeveloper is certified with 1.3 then you can run the 1.3 plugin successfully.
    Hi,
    I have made an infobus applet and deploy it with the OAS407.
    Now I have seen, that each time I load the applet from the
    OAS407 the applet create 15 files in my temp-folder with the
    prefix jar_cache (for example: jar_cache40989.tmp).
    There is no problem with creating but there is a problem with
    deleting because there is no mechanism for automatic deleting.
    So I have to delete these files manually but I think that this
    is unuseable for end-user.
    Does anybody know how to bypass this problem ?
    Thanks.
    Nils<HR></BLOCKQUOTE>
    null

  • Java Applets and Executing Files

    Hi I have written an applet that pops up when accessing a URL. I am trying to run an executable file from a button press in the applet. The executable is stored localy on my machine but I can not seem to acceess the executable.
    Any Ideas??
    Cheers JJ

    http://java.sun.com/j2se/1.4.2/docs/api/java/awt/Robot.html

  • JRE 1.4.x Plugin - Signed Applets and Weird Behaviour (Policy)

    Hello.
    I have recently experienced some strange behaviour related to signed applets and policy files in JRE 1.4.2-b28 ( a friend got the same behaviour in a flavour of 1.4.1-xx as well ). Both tests were on Windows 2000 Professional platforms.
    Initially my unsigned applet, which attempts socket connections to a server different from the download location, fails with security exceptions ( as expected ). Then I did the following to sign the applet jar and configure my environment
    Steps: 1) Import "trusted CA" certificate into ${java.home}/lib/security/cacerts. (JRE home outside the JDK)
    2) Signed the jar using jarsigner and a certificate generated from the "trusted CA" (Entrust CA and certificate).
    3) Imported the signing certificate into the Java plugin using import in the plugin control panel.
    4) Created a new keystore (keytool,jks) and imported the signing certificate into the keystore with alias "developer". The keystore is stored in the user home as .keystore.
    5) Created a .java.policy for the user and attaching the keystore in 4) to it. ( also stored in user home ).
    6) Used the policy tool to grant socketpermissions to the specific codebase ( testing with file:/C:/test/* initially ) signed by "developer"
    After this, when I ran the test page under IE 5.5SP2 and Netscape 7.1 it worked without any security exception. Ditto for using the appletviewer and the policy file I created for the user.
    The weird part occurred when I removed the policy entry from the user policy file. After doing this, Netscape and IE still allow the applet to execute - somehow remembering that it was granted permissions at some point. The appletviewer does not allow it to execute, generating security exceptions.
    It appears the old policy is being cached somewhere, but I cannot find where. If I replace the applet jar with an unsigned version it does fail in IE and Netscape. I tried cleaning the plugin cache and removing the "deployment.certs" files related to the users but still get the same behaviour.
    Does anyone know where the old policy information is being stored ? Does anyone know how to revoke the permissions so that I am restored to my original base environment ( no permissions for "designer" signed applets ) ? Would attempting to utilize the AccessController.doPriveleged( xxxx ) operations in JDK 1.4 avoid all of this confusion with policy files, keystores and certificate storage ? After all the messing about I would like a zero-footprint alternative ( or minimzed footprint anyway ).
    Any ideas would be most welcome.
    Regards,
    James.

    Hello Again.
    I am either enlightened or confused at this point. I found that as long as all of my related Jars are signed ( even by self-signed certificates ) I am granted SocketPermissions for calls outside of the originating server. Unsigned code is refused, but even when the Jars were signed using a self-signed certificate the Socket calls were allowed.
    Am I experiencing the appropriate behaviour in this case ( which would mean not having to utilize policy files to distribute an applet that uses calls to arbitrary servers - e.g. JavaMail ) or am I suffering from something damaged in my environment ?
    It has been a long time since I played with signed applets and I am having difficulty determining what operations require policy file entries/AccessController.doPrivileged() calls and which are granted when a user elects to trust a signed applet without policy.
    Any assistance in clearing up my confusion would be appreciated.
    Regards,
    James.

  • Security issues with applets and windows Vista when printing to file

    Hi, everyone
    I am currently developing an application that prints out the result of some calculations.
    from a Javascript file, the output finally ends up in a java applet that should print the file in a special printer.
    For debugging purposes I have created a File printer that creates a file from the output comming to the printer; this way I can debug what commands the printer is receiving.
    This worked well on Windows Xp; Vista always asks for permissions for the applet, and altough I guarantee these permissions, printer is not allowed to create the output file and reports an error writing
    after a little research, I have found that java applets have all permissions when certificated as trusted applications; all but file creating permissions
    anyone has any idea of how could I fix this problem?
    Thanks in advance

    HI,
    Have you actually signed your applet? If the signers certificate is the trusted key store for Java it should treat your applet as trusted. You can use a self signed certificate for testing as long as the cert is in the trusted key store.
    Some links that might help:
    [http://java.sun.com/j2se/1.4.2/docs/tooldocs/windows/keytool.html]
    [http://java.sun.com/j2se/1.4.2/docs/guide/plugin/developer_guide/rsa_signing.html]
    Cheers,
    Shane

  • Applets and File I/O

    As an attempt to familiarize myself with Java, I decided to create an applet to display my collection of collectible trading cards so that other collectors could view it and offer trades. The data is stored in a .txt file, which the applet reads when setting things up. The data is never edited by the applet, only read. Everything is working fine until I put the applet on the web page.
    At first, I ran into the security problem that it appears others have run into, and I searched the forums to figure out what to do about that. I'm not getting security exceptions any longer, I'm merely getting a "File Not Found" issue instead.
    The data file is included in the .jar file, so I didn't think I'd have to do anything other than this when I try to open the file stream:
    dataFile = new Scanner(new BufferedReader(new FileReader("MTDBData.txt")));;
    But this is what I see when I attempt to open the page:
    mDNSResponder: mDNS_SetPrimaryInterfaceInfo V4 address - incorrect type. Discarding.
    Exception: MTDBData.txt (No such file or directory)
    java.lang.NullPointerException
    at ListData.initializeListData(ListData.java:194)
    at MTDBManager.init(MTDBManager.java:129)
    at MTDBApplet.init(MTDBApplet.java:10)
    at sun.applet.AppletPanel.run(AppletPanel.java:378)
    at java.lang.Thread.run(Thread.java:613)
    I also tried putting the data file in the same directory with the .jar file on the web page, but that isn't working either. Does the first line indicate that I am doing something wrong when generating the security keys? Or do I need to preface the filename with pathing information in order for the applet to find it?
    Any assistance would be appreciated. Thanks!
    -- Josh

    After some investigation, I added a getCodeBase() before the file name to tell it explicity where to look. Now I'm seeing this:
    Exception: http:/(URL omitted)/mtdb_data.txt (No such file or directory)
    java.lang.NullPointerException
         at ListData.initializeListData(ListData.java:215)
         at MTDBManager.init(MTDBManager.java:136)
         at MTDBApplet.init(MTDBApplet.java:10)
         at sun.applet.AppletPanel.run(AppletPanel.java:378)
         at java.lang.Thread.run(Thread.java:613)
    I changed the file name from before and omitted the first part of the URL for privacy reasons. But what baffles me is that I can paste the full URL for the file it says it can't find into my browser, and the file pops up exactly as I would expect. I've tried this on two different web pages, and the only differece in the error is the first part of the URL, so I know the getCodeBase call is working properly. Has anyone seen this problem where it can't find the file despite the URL being correct? More importantly, does anyone know what to do about it?
    -- Josh

  • How to access a file via Applet and JavaScript

    I want to copy one file on the client machine from one place to another place from a Java Bean.
    To do this I created an applet and a Java Bean as follows:
    import java.applet.*;
    public class FileUtils extends Applet {
        public void copyFile(String src, String dest)  {
        private String source, destination; // setters/getters are there of course
        public void copyFile(ActionEvent actionEvent) { // Bean
            FacesContext fctx = FacesContext.getCurrentInstance();
            ExtendedRenderKitService erks = Service.getRenderKitService(fctx, ExtendedRenderKitService.class);
            String command = "var s = '"+ source +"'; var d ='" + destination +"'; " +  " document.fileUtilsApplet.copyFile(s, d); ";
            erks.addScript(fctx, command);
        }Then I added the APPLET tag referencing the above class in the page fragment:
                    <f:verbatim>
                        <applet code="FileUtils.class" name="fileUtilsApplet" height="30"
                                archive="/context-root/Applet.jar"
                                width="200">
                        </applet>
                    </f:verbatim>From the Java console I can see the jar is successfully downloaded, but when the code in the bean is executed, the JavaScript code does not seem to do anything, as if the "copyFile" public method was not called at all and no output in the Java Console as well.
    Note that I already followed the guidelines at http://www.oracle.com/technetwork/developer-tools/adf/learnmore/71-adf-to-applet-communication-307672.pdf .
    Do you have any ideas?

    Ok, I can see the permission problem now:
    java.security.AccessControlException: access denied (java.io.FilePermission c:\myfile.txt read)
         at java.security.AccessControlContext.checkPermission(Unknown Source)
         at java.security.AccessController.checkPermission(Unknown Source)
         at java.lang.SecurityManager.checkPermission(Unknown Source)
         at java.lang.SecurityManager.checkRead(Unknown Source)
         at java.io.FileInputStream.<init>(Unknown Source)
    Edited by: user10047839 on 1-feb-2013 7.29
    signing the Jar and downloading the certificate permanently does not change anything in Firefox. The Java console keeps giving the above exception.
    Any idea?

  • Applets and files

    Hello!
    I have built an applet which have to write, read, delete some files. I have write the permissions in the java policy file and I have no problem to run the applet with appletviewer. However, when I try to run it with the web browser the applet write the files but then it doesn't find them when the applet needs to read the files. I have been reading and I think I have to change my initial folder in the java console but I`m not sure about how I have to do it.
    Thank you in antitipation for your help.

    You can find the java policy file in your Java folder Java/JRE/1.4.1/lib/security/java.policy.
    You have to open java.policy with the notepad and add the permissions you need and save the file. For example, if you want to allow your applet to read, write and delete files you have to add this lines to the java.policy file.
    grant {
    permission java.io.FilePermission "<<ALL FILES>>", "read,write,delete";
    permission };
    Anyway, google java applet permissions and you will find web pages where you can learn to use grant.

  • Java Applet and Perl - writing files

    OK. i need to be able to write a file to a folder on the webpage that the applet is on so that i can access these files for later use. i also understand that u need to use a server to do this. fortunately my web hostingsupports Perl but i don't know the first thing about it.
    i need someone to help me understand how to create a perl server so that the applet can write files.
    Can anyone show me either a thorough tutorial or explain it step by step as i do not know much about servers or servlets.

    I assume you are putting up an applet that can have a user search through his hard drive folders for a particular file, then want the file sent to a servlet on the server? If so, read up on the html tag <input type="file"
    and find some examples on how to use it. I dont know enough about applets to tell you how to do it with an applet.

  • Read, Write and create files from java applet.

    Dear All,
    I have created a two files. One is applet and one application file. I am creating a instance of application file in applet. Application file is used for reading, writing and creating files. When I invoke applet from broser it dipslays error wrt file access permission. From the forum search I know that we need to sign the applet / edit the java policy to run the code locally. Final delivery of my code should execute on different system. Its not web. I have created a html page on submitting the form it invokes applet to read the form values from param and needs to update the values in xml file located locally. Please help me on how I can proceed with this fix.
    Thanks in advance.

    Sorry if I have not stated the problem clearly. I need to update content to files hosted in local system using java applets.
    I belive there are two ways to achive that.One with jar signer and one with modifying the java policy file. But this application needs to be installed in different system locally as I have created a application with webpage as useinterface and need to update the content in local files on submission. Not sure on how to modify the java.policy files in each end user system and whats the value we need to update in java policy file. Please help me on the steps to be followed

  • Applets and classes in jar files

    I have placed an applet and a group of classes that the applet uses in a jar file.
    The classes are grouped in their own files in a short directory tree within the jar file.
    When the applet is loaded by the browser on a client with the usual CODE="appletname.class" and ACRCHIVE="jarname.jar" statements, are the related class files and the directory tree also loaded into the client? Or do they remain at the server to be used by the applet as necessary?

    I'd say the entire JAR will be downloaded.

  • 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.

  • Calling JSP file from applet and passing a parameter in POST form

    Hi,
    Can anybody help me. I want to call a JSP page from within a applet and to this JSP page i want to pass the query which the applet has created in POST method.
    I want to refresh the applet page with the new JSP page by passing the query object so the jsp page with take this query, and display the resultset
    Thanks in advance
    JK

    Review
    URL.openConnection()
    and HttpURLConnection

  • IDES for writing Java card applets and converting the applets as CAP FILE.

    I have developed a JAVA CARD APPLET , FindMFValueJCA.java . It gets compiles in net beans 6.0 But while converting the applet to CAP file i am getting some errors. Is there any other IDES which take care of converting the CAP files

    What's the Java version you are using?
    As the java card tool kit has version dependencies. If you are using java_card _kit 2.2.2 then 1.5 is fine.                                                                                                                                                                                                                                                                                                   

Maybe you are looking for

  • XML Publisher 5.6 Standalone for Solaris

    When will this version be ready? I see the Windows and Linux versions are already t here. Message was edited by: naveeny

  • Disable Clamshell Mode?

    Currently, I have a 3rd generation MacBook Pro hooked up to an external TV via the DVI output. When I close the laptop lid, the external TV becomes the primary (and only) active monitor, while the laptop stays awake. I believe this is called Clamshel

  • Can I Modify .MDB VBA From Access 2010?

    Hello: Currently, I am using Access 2010 and 2013.  One of my clients is still using an mdb file created by Access 2003.  They don't want me to upgrade to .accdb, but want me to modify the VBA code. Prior to today, I had a version of Access 2003, but

  • Camera Calibration - Profiles. How To??

    I'm very new to Lightroom. I'm using a trial version of 2.6 until I get my full paid version in the mail, hopefully in one or two days. In the develop module on the CAMERA CALIBRATION tab I have no choices for profiles. The only one there is EMBEDDED

  • Defaulting messages to a particular message area

    Hi All, I have two applications running on same screen, One at top and another one just below it  . Both have their own message area. When applications are run individually, messages are getting shown in their respective message area. However on scre