Hey guys I'm doing this program that prompts a user a menu and one of the options is to save a file that is already made in the same directory to a new file which hasn't been made. I dont have a problem doing so, but after it is done saving my original file keeps getting erased. here is some of the code and maybe one of you can help me.
public void save() throws Exception
{
PrintWriter out=null;
try{ out=new PrintWriter(new FileWriter(fName));}
catch(IOException e){}
try{ out= new PrintWriter(new FileWriter("outfile.txt"));}
catch(IOException e){}
for(int i=0; i<cCount; i++)
{
out.println(uWords[i]+" "+uCount);
}
System.out.println(fName+" is saving...");
System.out.println();
System.out.println(fName+" has been saved.");
System.out.println();
System.out.println();
out.close();
}//ends save method
The teacher says that the out.close() is important because if you don't close it the memory in the file will be lost, but as you can see i do close it, but am i closing it in the wrong place?
Thanks in advance