Results 1 to 12 of 12
  1. #1
    Ranu is offline Member
    Join Date
    Jun 2010
    Posts
    13
    Rep Power
    0

    Default file access from applet

    I have created a folder which contains the index.html file describing an applet name newapplet.java.In this newapplet.java it accesses a file which is in same folder and its contents are to be read.I have uploaded this folder in webserver.But I cannot see the contents.But when I test this applet from my machine I can see the contents.Where is the problem?

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,618
    Rep Power
    25

    Default

    Are there error messages in the browser's java console?
    Please copy and post them here.

    I don't know how your HTML worked if it references newapplet.java vs the class file.

  3. #3
    Ranu is offline Member
    Join Date
    Jun 2010
    Posts
    13
    Rep Power
    0

    Default

    Only it gives FileNotFoundException.

  4. #4
    Zack's Avatar
    Zack is offline Senior Member
    Join Date
    Jun 2010
    Location
    Destiny Islands
    Posts
    692
    Rep Power
    5

    Default

    We cannot help you with this much information... provide the code (in [code] tags) used to call the file as well as the full stack trace you get with the error message, please.

  5. #5
    Ranu is offline Member
    Join Date
    Jun 2010
    Posts
    13
    Rep Power
    0

    Default

    import java.applet.Applet;
    import java.io.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.applet.Applet;
    import java.awt.FlowLayout;
    import java.awt.Label;
    import java.io.BufferedReader;
    import java.io.InputStreamReader;
    import java.net.URL;

    /**
    *
    * @author Adminstrator
    */
    public class NewApplet extends Applet implements ActionListener{

    /**
    * Initialization method that will be called after the applet is loaded
    * into the browser.
    */
    TextArea ta;
    public void init() {
    Button b=new Button("Read File");
    b.addActionListener(this);;
    add(b);
    ta=new TextArea();
    add(ta);
    }
    public void actionPerformed(ActionEvent e)
    {
    String line = null;

    try
    {
    URL textURL = new URL( getCodeBase() , "./Mech/mech.dat" );
    BufferedReader reader = new BufferedReader( new InputStreamReader( textURL.openStream() ) );

    // now read the lines one at a time
    while ( ( line = reader.readLine() ) != null )
    {
    add( new Label( line ) );
    } // close while loop

    reader.close();
    } // close try
    catch (Exception ex )
    {
    ex.printStackTrace();
    }



    }

  6. #6
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default

    Applets don't have file access! Did you sign your applet?
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  7. #7
    Ranu is offline Member
    Join Date
    Jun 2010
    Posts
    13
    Rep Power
    0

    Default

    Only signing will do..?or I have to make changes in policy file? plz explain if yes how it can be done

  8. #8
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

  9. #9
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,618
    Rep Power
    25

    Default

    it gives FileNotFoundException.
    What was the full text of the message? Was there anything about permission in it?

    How are you executing the applet? Loading an html file locally from your PC
    or from a server?

    If from your PC you can give the applet permission via your .java.policy file.

  10. #10
    Ranu is offline Member
    Join Date
    Jun 2010
    Posts
    13
    Rep Power
    0

    Default

    I am uploading the html file from my PC to the server.In fact I have uploaded the project created in NEtbeans IDE which has src folder containing the source file i.e, .java file.The html file is outside the folder of the project.Now for the applet to access the data file where the .dat file should be kept.??I am confused.

  11. #11
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,618
    Rep Power
    25

    Default

    Are you saying that all the files are on a server? and that you load the HTML file into your browser using an URL like:
    "http:// www.server.com/YourStuff/YourApplet.html"

    On the the server the html file, the jar file with the applet classes and the .dat file are all in the YourStuff folder.

    For the applet to access the .dat file from the same folder where the html and class files are, it should have a path matching its location relative to where the html is.
    Last edited by Norm; 07-28-2010 at 01:48 PM.

  12. #12
    Ranu is offline Member
    Join Date
    Jun 2010
    Posts
    13
    Rep Power
    0

Similar Threads

  1. Replies: 6
    Last Post: 02-10-2011, 10:55 AM
  2. File access
    By frenk_castle in forum New To Java
    Replies: 5
    Last Post: 04-30-2010, 01:34 PM
  3. Access Web-Camera through Java-Applet code.
    By Chetans in forum Java Applets
    Replies: 0
    Last Post: 03-29-2010, 05:58 AM
  4. How can I access the values within an applet?
    By Addez in forum New To Java
    Replies: 0
    Last Post: 12-18-2009, 04:57 PM
  5. Unable to access velocity.properties file from jar file
    By mjwoodford in forum New To Java
    Replies: 0
    Last Post: 10-09-2009, 02:46 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •