I created a function that saves a file with a custom extention ".nra"
however each time that i enter a file name, it throws ArrayIndexOutOfBoundsException
public static void SaveFileNra() throws Exception
{
if(gl.DataStack.isEmpty())
{
System.out.println("There is nothing to save!\n");
Menu();
}
else
{
System.out.print("Enter the directory you wish to save to (including final slash): ");
gl.Directory = new Scanner(System.in).nextLine();
File file = new File(gl.Directory + gl.RomName + ".rna");
if(file.exists())
{
System.out.println("Would you like to Overwrite " + gl.Directory + gl.RomName + ".rna?");
gl.m = new Scanner(System.in).nextInt();
if(gl.m != 1)
{
System.out.println("Sorry! Cannot make a file that already exists!\n");
Menu();
}
else
{
file.delete();
file.createNewFile();
}
}
file.createNewFile();
FileWriter fstream = new FileWriter(file);
BufferedWriter bw = new BufferedWriter(fstream);
if(gl.IncludeTextMacro = true)
{
for(gl.k = 0; gl.k < gl.MacroStack.size();gl.k++)
{
bw.write("; " + gl.MacroStack.elementAt(gl.k));
}
}
for(gl.l = 0; gl.l < gl.DataStack.size(); gl.l++)
{
bw.write(gl.DataStack.elementAt(gl.l));
}
System.out.println("\nFile " + gl.RomName + " was sucsessfully saved!");
Menu();
}
}
THE GL CLASS SO PEOPLE ARN"T CONFUSED
class globals
{
public boolean PadWithZeroes;
public boolean SkipUnknownOpcodes;
public boolean IncludeTextMacro;
public Stack<String> DataStack = new Stack<String>();
public Stack<String> MacroStack = new Stack<String>();
public int i, j, k, l, ix, LineNum, ch;
public int CurrentLocationDec = 0;
public int RomSize;
public String RomName;
public String Directory;
public int m;
}
Ideas?