signed applets weirdness

ok, so i signed my applet, and it has this code in it:


try{
			DataOutputStream file=new DataOutputStream(new BufferedOutputStream(
				new FileOutputStream(new File("file.txt"))));
			file.writeBytes("hello file");
			file.flush();
			file.close();
} catch(IOException exp){}

which is supposed to test how well i signed the jar. It does not show any exceptions but the file is not written.
Is the file supposed to be written inside the JAR or in its derictory. I checked every part of my JAR and the file isnt there. ???

The jar itself (once it’s in the cp) is read only. With a path like that it’s written into the current working directory… whatever that might be. Just search for that file and you might find it.

Btw the minimum catch block contains a printStackTrace(). Otherwise you won’t get a hint what went wrong (that is if something went wrong).

the file is actually written to the desktop :o, even though my working directory is 6 levels below it.
So there is no way to write the file to the derictory and then read it when i need to?

U dont have to put anything between the catch block braces. I tried that before i signed my applet and it threw exceptions as expected.

So there is no way to write the file to the derictory and then read it when i need to?

If you use the same path for reading, it works fine. Well, just create a subdir in the user dir (“user.dir” system property) with a leading dot (eg “.foo”).

U dont have to put anything between the catch block braces.

I know. I meant the minimum one should put there.

the problem is that when “file.txt” is read, it reads it from inside the jar and when i write it, its written on the desktop.

Another question (not related, but dont wanna start a new thread).

Suppose i have an array of bytes 60x1000. And depending on what the value is i wanna draw a sprite at certain position.


for(int i=0;i<20;i++)
for(int j=0;j<10;j++){
int x1=i*50,y1=j*50;
if(arr[i][j]==0)g.drawImage(img0,x1,y1,null,this);
else if(arr[i][j]==1)g.drawImage(img1,x1,y1,null,this);
else if(arr[i][j]==2)g.drawImage(img2,x1,y1,null,this);
...
else if(arr[i][j]==30)g.drawImage(img30,x1,y1,null,this);
}

I was wondering since the cell value corresponds to the image name, can i do something like this


for(int i=0;i<20;i++)
for(int j=0;j<10;j++){
int x1=i*50,y1=j*50;
g.drawImage("img"+toString(arr[i][j]),x1,y1,null,this);
}

not sure if that’ll work, but u get the idea

the problem is that when “file.txt” is read, it reads it from inside the jar and when i write it, its written on the desktop.

Use a complete path to read/write the configuration.

@The other question

Well, use arrays.

g.drawImage(tiles[map[x][y]],…); (tiles contains the tile images, and the 2d map array contains the indices)


g.drawImage(tiles[map[x][y]],...);

of course, me stupid . . . ;D

Few more questions.

  1. How can u determine at what speed an applet runs? CPU does not show it (my game runs at 4% CPU max, but on a slower computer it runs at 100% and really really slow).
  2. How much memory can Java handle and does it influence game speed? How many images or arrays? ( a rough estimate)
  3. How can I draw a bunch of stuff to an empty image and then draw the image on the screen. (Would it like kill the cpu or memory?)

Thanckxs ;D