java.io.IOException: Access Denied
843810Apr 18 2010 — edited Apr 22 2010Hello there, I'm switching from Microsoft's C# to Sun's Java. I'm still learning but I'm getting an exception saying java.io.IOException: Access Denied. The program runs fine in NetBeans console, but when I run it from a Jar file, it gives me that exception. Here's the code where it occurs.
File file = new File(filename);
boolean success = file.createNewFile();
if (success)
{
}
else
{
BufferedReader overwriteprompt = new BufferedReader(new InputStreamReader(System.in));
System.out.println("The file already exists! Do you want to overwrite it?");
String overwriteyn = overwriteprompt.readLine();
if (overwriteyn.contains("y") || overwriteyn.contains("Y"))
{
file.delete();
file.createNewFile();
}
else
{
Main.ShowMainMenu(true);
}
}
Please help! Thanks