Hi,
I am a high school senior with a little over 1 year experience with
Java. I am trying to create and write to a .txt file within an
applet. However, when my program is run, I get "java.security.AccessControlException: access denied (java.io.FilePermission Quiz.txt write)". I am trying to write a program that creates a Quiz text file. I believe the issue is that the file is being created in the wrong place. I am creating the file by using myOutFile = new PrintWriter(new FileWriter("Quiz.txt", b)); b is of the boolean data type. After thoroughly going through the classes FileWriter and PrintWriter I am unsure as to where the file is being created. I expected the method getCodeBase(), however, nowhere in the code did I see the method used to create the file within the same directory.
writer=new EasyWriter("Quiz.txt");
public EasyWriter(
String fileName)
{
this(fileName, null);
}
/**
* Constructor. Creates a new file. If the file exists
* can append to it.
* @param fileName the name of the file to be created
* @param mode if equals to "app" opens in append mode
*/
public EasyWriter(String fileName, String mode)
{
myFileName = fileName;
myErrorFlags = 0;
try
{
myOutFile = new PrintWriter(
new FileWriter(fileName, "app".equals(mode)));
}
catch (IOException e)
{
myErrorFlags |= OPENERROR;
myFileName = null;
}
}
Any help is appreciated.