I went through a java tutorial that allowed me to create a text file and write the words,\"20 Bruce Wayne\" in it. The last method that is called in the main class is named
When a file is "opened," the OS marks the file as locked, generally so it can't be deleted by other processes while it's being used. x.close()
undoes the lock, allowing the OS and other processes to do what it wishes with the file.
is used for closing the file which is opened in write mode because to reduce/to make secure our data we use close() method and it throws exception like (java.io.IOEXCEPTION) why means any method call with respect to object only because it is public void close() that means it is instance so it is calls with respect with object so in some times is there a chance to getting object to get null any method calls with respect to null reference then it getting NullPointerException so this is the code code in finally block means what ever files we open that and all relinquished in finally block
In addition to the answer of Sold Out Activist, when you are working with i/o operations, such as files, you are using a stream to add text to your file, or extract text from your file. This stream must be closed, with the method close(), when you are exiting your program, because you could lose data. It's like a saving operation, if you don't save your file (close the stream), you will lose the changes made on file.
See this example, and this.