Your approach to define the variables areis fine since you are trying to close using those variables in the finally block.
But throwing the FileNotFoundExceptionFileNotFoundException in the writeToLinewriteToLine is actually not required as there are no file related operations other than the write. This exception is likely to be thrown when the file is opened while initializing the goThroughgoThrough variable.