Exception handling
It is not customary to let the main method throw an exception. At the very least you can catch the base Exception
class and use printStackTrace()
to print the error message and related debug info.
IO handling
This program only deals with one file. However, it is good practice to remember to close every external resource. That includes files, database connections (and other related resources, like prepared statements and result sets), network sockets, etc. not closing resources may result in resource leaks that can escalate to JVM crash. Java 7 introduced the try-with-resources construct that allows the compiler to automatically handle resource closure as well as error handling.
Java 7 also introduced the "new io"
java.nio
package that improves IO handling in Java. theFiles.readAllLines()
is a convenient method that reads whole file intoList
ofString
s (and also internally handles the external resource). (alas, no equivalentwriteAllLines()
)
Naming conventions
gradesString
is a List of Double
items. the name is very confusing.