We help IT Professionals succeed at work.

can't see file in IE

rutledgj
rutledgj asked
on
83 Views
Last Modified: 2012-06-07
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;
      //}}
}
Comment
Watch Question

Commented:
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.)
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.