Bhayu Herwahyudi
Bhayu Herwahyudi

Reputation: 1

java.io.FileNotFoundException (Access is denied)

File posisifileXML = new File("namefile.xml");
Writer outXML = new BufferedWriter(new FileWriter(posisifileXML));
outXML.write(String1);
outXML.close();

I have created Java applet in Linux, the program is used to create a namefile.xml, when I'm accessing java applet from the browser (with that Linux) to create a file, it's worked. That file is saved in my home directory. But the problem is when I'm accessing that Java applet from the browser with another computer (Windows 7), then appeared an error:

java.io.FileNotFoundException:namefile.xml (Access is denied)

oh sorry, I want to create a file from client's computer (windows 7) to the server's computer via the client's browser (using java applet)..

What should I do?

Upvotes: 0

Views: 5938

Answers (2)

Andrew Thompson
Andrew Thompson

Reputation: 168815

File posisifileXML = new File("namefile.xml");

Never dump a File from an applet into the 'default directory'. Make that something like:

File posisifileXML = new File(
    new File(System.getProperty("user.home")), 
    "namefile.xml");

I want to create a file from client's computer (windows 7) to the server's computer via the client's browser..

An applet on the client computer can not create or access a File on the server, security aside. File objects just do not work that way.

In order to get information from the user to be saved on the server file-system, requires help from the server.

Upvotes: 0

PeakGen
PeakGen

Reputation: 22995

You should have posted the code :(

However, I have had the same issue because of the following two issues, when I was working with Applets

  1. The access was restricted by windows (sometimes user privileges can do it. i.e: in my machine, it's hard to access C:/Desktop for programs)
  2. Forgot to give the rights using Policy tool
  3. The program is seeking for an existing file, but there is no such

Upvotes: 1

Related Questions