Hello, I"m trying to delete a text file but to no avail.
Here is the code
File myFile = new File("test.txt"); Scanner input = new Scanner(myFile); String oldText = ""; while(inputOld.hasNextLine()) { oldText = oldText + inputOld.nextLine(); } input.close(); myFile.delete();
File is still there when I look. Path is correct, and the weird thing is if I create a new File in the code and point it an existing file without using scanners I can delete it.
Example is:
File myFile = new File("test.txt"); myFile.delete()
and that works... So my assumption is that because the file is being used by program I cannot delete it. How can I force my program to stop using the file since .close() method appears to not be working...