Not to be picky, but this is a real bad antipattern:
Never throw Exception out of convenience. Either rethrow the checked exceptions you find in your method, or handle them as far as you can. Checked exceptions are to check for certain handeable error conditions. Simply throwing exception hinder you in that.
also:
is another one. Always close streams in a finally (yeah I know, it’s just an example, it’s just a file… but just do it on principle - it will save you hours of pulling your hair out when it comes to databases):
BufferedReader reader = null;
try
{
reader = new BufferedReader( new FileReader( new File(fileName) ) );
String line;
while( (line = reader.readLine()) != null ){
text.add(line);
}
}
finally
{
// always handle Exceptions in finally blocks
// you don't want them to obscure an exception from the try block!
try
{
if(reader!=null) reader.close();
}
catch(Exception ex)
{
System.err.println("Warning: couldn't close reader - " + ex.getMessage());
}
}