Jump to content
xisto Community
abhatia923

Java Applets Access denied to file when applet is started

Recommended Posts

I am getting access denied to file when execute(compiled successfully) the following applet
Please help:

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);}}

Edited by yordan
Please do not forget the "code" tags when posting some pieces of code. (see edit history)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.