bookmark - Java Applets Access denied to file when applet is started

Java Applets - Access denied to file when applet is started

 
 Discussion by abhatia923 with 2 Replies.
 Last Update: July 18, 2010, 11:07 am
 
bookmark - Java Applets Access denied to file when applet is started  
    
free web hosting
 
I am getting access denied to file when execute(compiled successfully) the following applet
Please help:

CODE

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

public class counterApplet extends Applet{
public static int i=0;
public static String no="";
public static String pre="You Are Visitor Number: ";
public static String p="";

public void init(){
FileInputStream file=null;

try {file = new FileInputStream("counter");} catch(FileNotFoundException e) {System.exit(1);}
//load value and increment it
try{for(i=0;i!=10;) {i=(file.read());if(i==-1) {break;} else{no=no+(char)i;}}
i = Integer.parseInt(no)+1;}catch(Exception e){System.exit(1);}
//write new value
no=""+i;
BufferedOutputStream bu = null;
try {
bu= new BufferedOutputStream(new FileOutputStream("counter"));
bu.write(no.getBytes());}catch (FileNotFoundException ex) {ex.printStackTrace();} catch (IOException ex) {ex.printStackTrace();}
finally {
try {
if (bu != null) {
bu.flush();
bu.close();}
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
public void start(){}
public void paint(Graphics g){
p=pre+no;
g.drawString(p,20,30);}
}

Fri Jul 16, 2010    Reply    New Discussion   


If you think about where applets execute, you will find that a counter makes no sense.

Sun Jul 18, 2010    Reply    New Discussion   

Quickly Post to Java Applets Access denied to file when applet is started w/o signup Share Info about Java Applets Access denied to file when applet is started using Facebook, Twitter etc. email your friend about Java Applets Access denied to file when applet is started Print
Reply / Comment Ask a Question? Share / Bookmark E-Mail a Friend Print

Processing   Processing (0)