Using BufferedReader to read lines of a file into a list To help improve my proficiency with Java, I would like to know how should I close these FileReaders as I have come across multiple answers, and what could I do better with this block of code?

/**
 * Returns a Vector&lt;String&gt; object that that can be parsed into classes.
 * The file arugment must specify a realative or aboustle adress to the file.
 * @param file to read
 * @return
 */
public static ArrayList&lt;String&gt; read(File file) {

    ArrayList&lt;String&gt; data = new ArrayList&lt;String&gt;();

    String lineRead;

    try {

        FileReader fr = new FileReader(file);
        BufferedReader br = new BufferedReader(fr);

        while ( (lineRead = br.readLine()) != null ) {
                data.add(lineRead);                
        }

        br.close();
        fr.close();

    } catch(IOException e) {
        e.printStackTrace();
    } 

    return data;
}
Since Java 7, you can make use of try-with-resources, which would change the implementation to:

try (BufferedReader br = new BufferedReader(new FileReader(file))) {
    while ((lineRead = br.readLine()) != null) {
        data.add(lineRead);
    }
} catch (IOException e) {
    ...
}


Some other tips:


Your documentation is not telling the truth and incomplete, you have to add some return documentation. Also, for parameters, the first string represents the name, and what follows is the explanation. So it should be more like e.g. @param file the file to read all lines from.
Return the interface instead of the implementation, i.e. return List instead of ArrayList, which means you can always change the implementation.
Never just print the stack trace, wrap and throw an (unchecked) exception or log. For more information as to why, see why printStackTrace is considered bad practice. In case you want to propagate the exception nonetheless, you can wrap it in another exception, e.g.:

try {
    ...
} catch (IOException e) {
    throw new UncheckedIOException(e);
}



This example may be used when the method this code is executed in does not declare to throw a checked Exception. But it all depends on the case at hand.


BufferedReader has a lines method returning all String lines as a stream. With this, you could also implement it as follows:

return br.lines().collect(toList());



I statically imported Collectors#toList. Notice how this results in a List and not an ArrayList.