Code to read local notepad.txt from applet

Hi.
Further to my (unanswered) queries about reading a notepad.txt file from the local directory i.e. the same directory from which the html and applet were launched, the following code is supposed to be able to read the local file. It failed to do so both in Netscape 7.1 and in IE5
I've also received conflicting advices : some says we can read local files without using a signed applet or chaning the ACL, whereas others I'll need to use signed applets and / or acl to allow the applet to read a local file.
My research has shown that java applets are supposed to be able to read local files. Has something changed:
public class FileAccess extends Applet
   implements ActionListener {
   Button loadButton, saveButton;
   TextField filename;
   TextArea  content;
   String browserName;
   boolean securitySupported = false;
   public void init() {
     setLayout(new FlowLayout());
     Label label =
       new Label("Simple file editor");
     add(label);
     loadButton = new Button("Load");
     saveButton = new Button("Save");
     add(loadButton);
     add(saveButton);
     loadButton.addActionListener(this);
     saveButton.addActionListener(this);
     filename = new TextField(20);
     add(filename);
     content = new TextArea(5,20);
     add(content);
     browserName = System.getProperty("java.vendor");
     if (browserName.indexOf("Netscape") > -1)
        securitySupported = true;
     setSize(200, 200);
   public void actionPerformed(ActionEvent evt)  {
     if (securitySupported) {
        if (evt.getSource() == saveButton) {      
           PrivilegeManager.enablePrivilege("UniversalFileAccess");
           try {
              FileWriter aWriter = new FileWriter(filename.getText(), false);
              aWriter.write(content.getText());
              aWriter.flush();
              aWriter.close();           
           catch(Exception e) {
             e.printStackTrace();               
        else if (evt.getSource() == loadButton) {
           PrivilegeManager.enablePrivilege("UniversalFileAccess");
           try {
              BufferedReader aReader  =
                 new BufferedReader
                    (new FileReader(filename.getText()));
              content.setText(aReader.readLine());
              aReader.close();           
           catch(Exception e) {
             e.printStackTrace();               
      else {
        getAppletContext().showStatus("security not installed");
}

Hi acinhk,
I read your note with great interest. I am trying to solve almost exactly the same problem as you are -
Reading a .txt file in IE5 from the same directory where the html and the applet were lauched.
Your code looks fine to me.
My code is very similar, and again generates a security exception - as I am having the same problem you had getting around Java security.
If you have been able to solve the problem, can you please let me know what you did.
Any modifications to your sample code that actually made it work would be greatly appreciated.
Also, is signing the applet to read a local file under IE5 really necessary ?
Can the file be read from the local IE file system without signing the applet ?
Please let me know your thoughts.
Thanks !
drbob

Similar Messages

  • Sample code to read a text file from UNIX directory.

    I am using 9i Developer Suite, application server is 9.0.4. I want some help on how to read a flat file from UNIX environment. A sample code could be very helpful.
    In windows, i use this kind of code:-
    I declare an object & then write to a file using these sample staements:-
    file_handle text_io.file_type;
    filename := 'd:\ran\egs\uninvoiced.txt';
    file_handle:=text_io.fopen(filename,'w');
    text_io.put_line(file_handle, 'MOBILE NO '||'COUPON NO ' || 'DATE');
    I hope, my question is clear. Please help in solving the doubt.
    Regards.

    filename := 'd:\ran\egs\uninvoiced.txt';This is a Windows directory, so it won't work on Unix.
    For the rest of the code: see examples in the Forms Builder Online Help.

  • Sensirion EKP-3 Code to read the raw ticks from the SDP6xx Pressure Transducer with LabVIEW

    Guys:
    I have seen the post here about the Temp Humidity sensor: Ref: http://forums.ni.com/t5/forums/replypage/board-id/170/message-id/749141
    Pardon the post under a new topic but I was advised to post it in a "new thread"... With the Device name in the title..  If this is a no-no let me know...
    Here is a question for the EKP-3 using the USB for the SDP6xx Here is an overview of what I am looking for... 
    http://www.screencast.com/t/RUDOisSvqC
    I have the Sensirion EK-P3 Stick to talk to the pressure transducer..
    This stick is made by these guys: http://www.codemercs.com/349/
    My question is how did you figure out the binary code to read the T and RH from the  iowkit.dll
    I want to read the RAW TICKS from the device that represent pressure. They go from 0 - 65535 and I have spied on it with WireShark and can not wrangle the binary code to read the raw ticks I am after.
    I made a video you can look at to see what I want from my learnings from this post: 
    http://www.screencast.com/t/UnCTJtvWLe
    I attached the DLL as well (Just rename it to iowkit.dll because LabVIEW does nol like dll's in attachments... so you do not have to mess with the msi.
    You may contact me directly at [email protected]
    Thanks!
    Dave Korpi
    Ref: http://forums.ni.com/t5/forums/replypage/board-id/170/message-id/749141
    Attachments:
    SHT75_IOWarrior.llb ‏139 KB
    iowkitdll.txt ‏71 KB

    Cameron... Wondering if you knnow how to get a 2's compliment for a 12 bit value in LabVIEW?
    I am looking to get the code to communicate to this top secret Sensirion product.
    Anyone know if I am properly sending the commands at 1, 2 and 3 of the image below?
    At issue, I think, is getting the two's compliment of the two 8 bit registers at Data LSB and Data MSB using LabVIEW...
    I have been working with the wizards at http://www.codemercs.com/258/?L=1 who have been EXTREMELY helpful.
    They have an AWESOME I2C to USB converter that you can get OEM devices to work for your I2C project. It is a single channel version of the NI-8451
    Anyone out there can figure this out so I can read the RAW TICKS from the Sensirion SDP6xx product line?
    Thanks a million! 
    Feel free to contact me at 831-455-0418 (pacific time) or [email protected]
    Attachments:
    SensirionCalls.png ‏121 KB
    Sensirion_Differential_Pressure_SDP6x0_Sample_Code_V1.pdf ‏97 KB
    LabVIEW_IOWarrior_V150Second.zip ‏1403 KB

  • Read Locals (using ParallelModel) from LabVIEW

    Hi
    I'm trying to read Locals from a ParallelModel execution using LabVIEW.
    I thought this might work:
    ThisContext.Thread.GetSequenceContext(1).Locals."NameOfLocal", but it did't work
    Any suggestions?
    regards
    Richard

    Hi,
    You need to used the Execution reference for the TestSocket.
    Get a reference to the Thread and use Thread.GetSequenceContext() to get a reference to the SequenceContext.
    Get a PropertyObject from the SequenceContext using SequenceContext.AsPropertyObject() then you can use the GetVal or SetVal methods.
    Hope this helps
    Regards
    Ray
    Regards
    Ray Farmer

  • How to read local drive file from jsp?

    please help me

    SirivaniG wrote:
    anyone help me out how to read text file which is in server using jspIn Other Words "Give me teh codez"!
    Make an attempt yourself (search the tutorials for some relvant examples), and then, if you still have problems, post that code and we will help, but we are not going to "give you teh codez"! Ugrent!!!!!!!!!!!!

  • ABAP Code to Read Characteristic from Another DSO

    Gurus and Experts,
    Plain and simple, I need a piece of ABAP code that reads a characteristic value from a different DSO.
    Here is the story. I have a data flow from DSO Delivery1 to DSO Delivery2. I need to write a code in the start routine of the transformation to read Sales_Doc_Type from DSO Sales1. The condition is, if Delivery1-Ref_Doc_Nr = Sales1-Sales_Nr then Delivery1-Sales_Doc_Type = Sales1_Sales_Doc_Type.
    I am a beginner in SAP BI and know nothing about ABAP. But I do have experience in SQL and Java.
    Any help or links or direction will be appriciated. Thanks in advance.
    Herru

    Hello,
    I think there is a correction in your Ques. That there are two DSO Delivery1 and Sales1...... I Hope this is Ok.
    Tables Required:----  Go To SE11 and *<DSO_NAME>00 You will get active table for your DSO. EG. /bic/Delivary100 and /bic/sales100
    Logic In start Riutine:----
    1. Define structure in Global Def. for Sales1 DSO.
    2. Also Define Internal table in Global Def. (I hope you know the syntax)
    3. now you will find that start writing code from below.
            Inclue:------ Select Statement from Slaes1 DSO into itab for all entries in source package.
    4. Loop source_package assigning <result_fields>.
    read itab into wa where Sales1-Sales_Nr = <result_fields>-Ref_Doc_Nr.
    <result_fields>-Sales_Doc_Type = wa-Sales1_Sales_Doc_Type.
    endloop.
    This logic will work..........
    If still you are find it difficult then take some abaper help.
    Regards,
    Ankit.

  • Getting host name from applet

    Hi All,
    How can i get the local host name from applet ( Host name where the applet running) . While i tried with InetAddress i got only the loop back address 127.0.0.1. Can anyone help me out in this regard.
    Thanks in advance
    V.S.Saravanan

    When you say you tried the InetAddress, did you try the following?
    You could try creating a Socket connection back to the host/server URL from where the Applet was downloaded (you should have permission to do this). You can then get the local address of the Socket.
    Something like:
    String hostName = getCodeBase();
    Socket s = new Socket( hostName, portNum );
    InetAddress address = s.getLocalAddress();
    String hostName = address.getHostName();
    Eric

  • I can't read in a date from a txt file

    Im not sure of the code needed to read in a date from the text file, this is an example of the text file:
    1
    2
    2003
    ie,
    day
    month year
    I have to read in this date, this is the set method for the date:
    public void setPurchaseDate (int d, int m, int y)
    new Date(d,m,y);
    And this is the code that I have tried using to readin the date:
      PurchaseDate=(Integer.parseInt(line),Integer.parseInt(line),Integer.parseInt(line));now i know its wrong, I just dont know what the code should be!!
    Cheers

    ok, I am going to go through it and see what values I can and cant read in, here is the code i am trying to use:
    private void addx()
           FileReader fin;
           int noBooks;
           int itemNum;
           String title;
           String subject;
           double costNew;
           double costPaid;
           String isbn;
           double sellingPrice = 0;
           int noAuthors;
           int day;
           int month;
           int year;
            String seperator = "#";
            Book[] book = new Book[9];
            try
                fin = new FileReader("Books.txt");
                BufferedReader buff = new BufferedReader(fin);
                String line = buff.readLine();
                int count= 0;
                //read in Number of books
                noBooks=Integer.parseInt(line);
                while( line != null)
                    //Read in item number
                    itemNum = Integer.parseInt(line);
                    //Read in title
                    title = buff.readLine();
                    //Read in number of authors
                    noAuthors=Integer.parseInt(line);
                    //Read each line in as an author until number of authors reached
                    ArrayList authors = new ArrayList();
                    for(int i=0; i < noAuthors ; i++)
                        authors.add(buff.readLine());
                    //Read in cost new
                    costNew = Double.parseDouble(line);
                    //Read in subject
                    subject = buff.readLine();
                    //Read in ISBN
                    isbn = buff.readLine();              
                    //Read in purchase day
                    day = Integer.parseInt(line);
                    //Read in purchase month
                    month=Integer.parseInt (line);
                    //Read in purchase year
                    year = Integer.parseInt (line);
                    //Read in cost paid
                    costPaid = Double.parseDouble(line);
                    line = buff.readLine();
                    //Pass date, month and year values to array
                    Date purchaseDate =new Date(day,month,year);
                    //Pass values to constructor
                    if (line.equals(seperator))
                        book[count++] = new Book(itemNum, title, authors, subject, purchaseDate,costNew,costPaid,isbn, sellingPrice,noAuthors);
                  // line = buff.readLine();
                System.out.println(book.toString());
            catch(Exception ex)
                System.out.println(ex.toString());
             }

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

  • Code for how to read an integer array from the command prompt...

    hello,
    Could anyone give me the code for how to read an integer array from the command prompt...its very urgent!..

    If you are using a recent version of Java (5 or later) you can use Scanner:
    http://java.sun.com/javase/6/docs/api/java/util/Scanner.html
    That page has some example code on it, too.

  • Code for reading particular  fields from the file placed in application

    hi,
    code for reading particular  fields from the file placed in application server in to the internal table.

    Hi,
    Use the GUI_UPLOAD FM to upload the File into ur Internal Table.
    DATA : FILE_TABLE TYPE FILE_TABLE OCCURS 0,
             fwa TYPE FILE_TABLE,
             FILENAME TYPE STRING,
             RC TYPE I.
    CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_OPEN_DIALOG
      EXPORTING
        WINDOW_TITLE            = 'Open File'
       DEFAULT_EXTENSION       =
       DEFAULT_FILENAME        =
       FILE_FILTER             =
       INITIAL_DIRECTORY       =
       MULTISELECTION          =
       WITH_ENCODING           =
      CHANGING
        FILE_TABLE              = FILE_TABLE
        RC                      = RC
       USER_ACTION             =
       FILE_ENCODING           =
      EXCEPTIONS
        FILE_OPEN_DIALOG_FAILED = 1
        CNTL_ERROR              = 2
        ERROR_NO_GUI            = 3
        NOT_SUPPORTED_BY_GUI    = 4
        others                  = 5
    IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    READ TABLE FILE_TABLE INDEX 1 into fwa.
    FILENAME = fwa-FILENAME.
        CALL FUNCTION 'GUI_UPLOAD'
             EXPORTING
                  filename                = filename
                  FILETYPE                = 'DAT'
           IMPORTING
                FILELENGTH              =
             TABLES
                  data_tab                = itab
             EXCEPTIONS
                  file_open_error         = 1
                  file_read_error         = 2
                  no_batch                = 3
                  gui_refuse_filetransfer = 4
                  invalid_type            = 5
                  OTHERS                  = 6 .
        IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
             WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
        ENDIF.
    Regards,
    Balakumar.G
    Reward Points if helpful.

  • Problem with reading locale from moduleImpl

    I extracted the locale bundle data from module by getViewObjects and I stored it into hashtable,
    problem is that i allways get data from default locale and not from users locale settings.
    These code is running on java servlet.
    code:
    NameModuleImpl NameModuleTmp = (NameModuleImpl)Configuration.createRootApplicationModule(propertie1,propertie2);
    for(ViewObject vo:NameModuleTmp.getViewObjects()) {
    int c=vo.getProperties().size();
    Hashtable ht=vo.getProperties();
    Greetings

    hi Rok Kogovšek
    Maybe some information in this forum thread could be relevant:
    "ADF BC : using UI Locale to translate data (Steve M. example 95)"
    ADF BC : using UI Locale to translate data (Steve M. example 95)
    regards
    Jan Vervecken

  • Read XML from applet

    Hi there,
    I would like to read XML data from Applet,
    first of all is it possible?
    If yes then how and will I require any extra pugin other than Java Plug-in?
    Thanks

    Sure you can, as long as the applet has permissions to read the xml file. If it is in the same directory as the applet it should be ok.
    There is no need for an extra plugin. Here's a starting point:
    import javax.xml.parsers.DocumentBuilderFactory;
    import org.w3c.dom.Document;
    import org.w3c.dom.Element;
    import org.w3c.dom.NodeList;
    Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(<some stream>);
    Element data = doc.getDocumentElement();
    NodeList dbChildren = db.getChildNodes();

  • Reading Last line(record) from a txt file ina java

    Hi,
    I want to retrive the last line from a txt file.Can anybody help me??
    Thanx in advance

    In order to read the last line you must read all the lines before it. To read lines you can use the BufferedReader and LineNumberReader classes.
    Here's an example of how to read lines of text from a file:
    http://javaalmanac.com/egs/java.io/ReadLinesFromFile.html

  • How read a file from applet?

    Hello.
    I have an applet which is in a signed jar file. And a configuration xml file. All I want to do is to put it near the jar file and access to it from applet. But applet cannot find it. I just want to read it simply. Also I don�t want to put it in a specified location on the server and want to have it near the jar file.
    Thanks very much.

    Check the API doc for Applet (that's java.applet.Applet). You call myApplet.getDocumentBase() to get the base URL (directory). I believe the base URL returned is actually the base URL of the HTML doc which your applet is embedded in. Add your xml filename to the end of the path. Then look at the API doc for java.net.URLConnection. You can call myURLConnection.getInputStream() to get an input stream of your xml.
    Nick

Maybe you are looking for

  • I have the open new windows in a new tab option selected yet it still opens in the same window.

    Firefox v28.0, Mac OS X 10.9.2, 3.5 GHz Intel Core i7. Operating in safe mode. In the preferences menu I have the "Open new window in a new tab instead" box checked yet when I click on links the new page opens in the current window. If I control clic

  • How to use 2 GL for loss made on asset retirement w/o revenue ?

    how to use 2 GL for loss made on asset retirement w/o revenue. hello everyone i have some trouble. my company want to use 2 GL account for asset retirement example  some time use GL 6500001  some time use 6500002 in standard configuration AO90 , fiel

  • How debug a routine created in InfoPackage for Data selection ?

    Hi everybody, I decide to debug a routine create in InfoPackage. Here, the name of my ABAP routine: program conversion_routine form compute_TREATMENT_DATE When i execute the "/h" command to launch debugger, i don't see this routine in Call Stack... H

  • Date Format Issue in Session

    DECLARE err_mesg_out          NUMBER(1):=0; x     DATE; y     VARCHAR2(50) := Null; z     DATE; BEGIN select scheduled_date into x from CONTRACT_SCHEDULED_FULFILLMENT where CONTRACT_ID=94875672 and fulfillment_type_id=9; dbms_output.put_line('x ='||x

  • Ad Hoc provisioning - code sign error...

    I have a bit of a problem creating the ad hoc build for the app.... Here's what I did so far: 1. Created the AdHoc provisioning profile on the portal 2. Downloaded and installed it in Xcode 3. Copied the Release configuration as AdHoc 4. As suggested