create temporary file in java...

D

daniele

Hi guys,
i've an easy question for you. I've a jsf application, when i click on
a button a method starts that creates a temporary file, run an applet
that loads this file and when the applet ends the temporary file has to
be deleted.
What is my problem?
I've tried to create the temporary file with

String y="good";
File w=File.createTempFile("giu",".txt");
BufferedWriter b;
b = new BufferedWriter(new FileWriter(w));
b.write(y);



i've searched a giu.txt file but it doesn't exists!!!
Please help me to understand where is my error,thanks
 
J

Joe Attardi

i've an easy question for you. I've a jsf application, when i click on
a button a method starts that creates a temporary file, run an applet
that loads this file and when the applet ends the temporary file has to
be deleted.

Hi daniele,

An applet, by default, is not permitted to access the file system of
the computer it's running on. This is a security restriction.
There are ways around this, for example you can sign the applet to
allow it to run. Or, another option is to make it a regular application
launched via Java Web Start.
 
W

Wesley Hall

daniele said:
Hi guys,
i've an easy question for you. I've a jsf application, when i click on
a button a method starts that creates a temporary file, run an applet
that loads this file and when the applet ends the temporary file has to
be deleted.
What is my problem?

I suspect it is because you are confusing server side and client side
code. If you run the code below inside a JSF application (which is
essentially a servlet) the file will be created on your server. The file
will be placed in 'the default temp file directory' wherever that is (I
have never needed to use that particular method), it is probably /tmp on
unix.

An applet is downloaded by the browser and runs on the client, as
someone has already said, it cannot access the local filesystem without
specific steps, but if it could, it would be accessing the *client*
filesystem.

You could accomplish what you are trying to do by creating a temporary
page on the server with the information in and having your applet access
this URL. Applets ARE allowed to connect back to the server they were
downloaded from without signing.

Either this, or, when you generate your applet page, include parameters
to the applet with the data you are trying to pass.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,270
Messages
2,571,102
Members
48,773
Latest member
Kaybee

Latest Threads

Top