I need to fix the following code so that it follows proper input validation and data sanitization procedures. It takes a txt file of a list of email addresses from a command line argument.
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
public class Example {
public static void main(String[] args) {
String filename = args[0];
BufferedReader inputStream = null;
String fileLine;
try {
inputStream = new BufferedReader(new FileReader(filename));
System.out.println("Email Addresses:");
// Read one Line using BufferedReader
while ((fileLine = inputStream.readLine()) != null) {
System.out.println(fileLine);
}
} catch (IOException io) {
System.out.println("File IO exception" + io.getMessage());
} finally {
// Need another catch for closing
// the streams
try {
if (inputStream != null) {
inputStream.close();
}
} catch (IOException io) {
System.out.println("Issue closing the Files" + io.getMessage());
}
}
}
Aucun commentaire:
Enregistrer un commentaire