Link to home
Start Free TrialLog in
Avatar of rutledgj
rutledgj

asked on

can't see file in IE

I have this sample code where I'm trying to open a file to read in some data. ALL files are in the same directory as the html file.

HTML FILE:

<HTML>
<BODY>
<APPLET CODE="AreaCode.class" width=500 height=400>
</applet>
</body>
</html>


Java Code:

/*
      A basic extension of the java.applet.Applet class
 */

import java.awt.*;
import java.applet.*;
import java.io.*;
import java.util.*;
import java.awt.event.*;


public class AreaCode extends Applet
{
      public void init()
      {
            // Take out this line if you don't use symantec.itools.net.RelativeURL or symantec.itools.awt.util.StatusScroller
            symantec.itools.lang.Context.setApplet(this);
      
            // This code is automatically generated by Visual Cafe when you add
            // components to the visual environment. It instantiates and initializes
            // the components. To modify the code, only use code syntax that matches
            // what Visual Cafe can generate, or Visual Cafe may be unable to back
            // parse your Java file into its visual environment.
            //{{INIT_CONTROLS
            setLayout(null);
            setSize(428,330);
            setBackground(new Color(12632256));
            label1 = new java.awt.Label("Enter Area Code");
            label1.setBounds(48,24,132,28);
            label1.setFont(new Font("Dialog", Font.PLAIN, 16));
            add(label1);
            codeIn = new java.awt.TextField();
            codeIn.setBounds(48,60,90,26);
            add(codeIn);
            label3 = new java.awt.Label("The following cities have this areacode: ");
            label3.setBounds(48,120,276,26);
            label3.setFont(new Font("Dialog", Font.PLAIN, 16));
            add(label3);
            areaOut = new java.awt.TextArea();
            areaOut.setBounds(48,168,264,156);
            add(areaOut);
            button1 = new java.awt.Button();
            button1.setLabel("Search");
            button1.setBounds(276,12,60,36);
            button1.setFont(new Font("Dialog", Font.PLAIN, 14));
            button1.setBackground(new Color(12632256));
            button1.addActionListener(new bListener());
            add(button1);
            label2 = new java.awt.Label("Searching...");
            label2.setBounds(252,72,96,26);
            label2.setFont(new Font("Dialog", Font.PLAIN, 14));
            label2.setForeground(new Color(16711680));
            label2.setBackground(new Color(16777215));
            add(label2);
            //}}
      }

public class bListener implements ActionListener
{

      public void actionPerformed(ActionEvent e)
      {
          StringBuffer sb = new StringBuffer(5000);
          String sg = null;
        
          DataInputStream input = null;
            String dir = new String("c:\\areacode");
            String file = new String("areacode.txt");
            File file = new File(dir,file);



          try{
          input = new DataInputStream(new
                     FileInputStream(file));
          }
          catch(IOException ie)
          {
              areaOut.append("Can't open file areacode.txt");
              
          }
          try{
           sg = new String(input.readUTF());
          }
          catch(IOException ae)
          {}
          areaOut.Text(sg);
      }    
       }  
      }
          
          

file areacode has numbers and strings in it in the format:
336 = North Carolina(Greensboro, Winston-Salem)

This works in the appletviewer but not in IE. I get the
message in the areaOut box "Can't open file areacode".    
          
      
      //{{DECLARE_CONTROLS
      java.awt.Label label1;
      java.awt.TextField codeIn;
      java.awt.Label label3;
      java.awt.TextArea areaOut;
      java.awt.Button button1;
      java.awt.Label label2;
      //}}
}
Avatar of Twix
Twix

Hello Rutlegj,

Okay, your problem is going to be that you are loading with referance to a directory that is not inside the security of IE.

    DataInputStream input = null;
//          String dir = new String("c:\\areacode");
//This is a referance to the directory above the applet.
//Not allowed, file should read:
            String dir = new String(".\");
            String file = new String("areacode.txt");
            File file = new File(dir,file);

In addition, by default the security must be set down in IE and Netscape. It is very involving with both of these. I can get a .reg file for IE that sets it to allow local files and socket connections, but you are much better off running from a web server.

Netscape is just as messy, but I don't have a file for that. Though the proper documentation should be aviable from Netscape to change this. (Again, nothing you can do from the GUI.)
ASKER CERTIFIED SOLUTION
Avatar of Twix
Twix

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial