You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Food for thought: if the code which processes the file throws an exception, then you will never call csvReader.close(). This can cause your code to leak file handles and other resources, which would be problematic in a real application with a high volume of requests.
Normally you would handle this by writing something like:
CSVReaderHeaderAware csvReader = null;
try {
csvReader = ...
// process the file
} catch (IOException ..) {
// file doesn't exist (although it could be another error like access denied)
} catch (/* other errors thrown by CSV library */) {
} finally {
if (csvReader != null) {
csvReader.Close();
}
}
try(CSVReaderHeaderAware csvReader = new CSVReaderHeaderAware(new FileReader(filePath))) {
// process the file
// no need to close it manually
} catch (IOException /* or whatever */) {
// ...
}
Food for thought: if the code which processes the file throws an exception, then you will never call csvReader.close(). This can cause your code to leak file handles and other resources, which would be problematic in a real application with a high volume of requests.
Normally you would handle this by writing something like:
Fortunately, modern Java has better syntax for it, but I don't know what version app engine uses. See this article: https://www.infoq.com/news/2010/08/arm-blocks/
Originally posted by @antmar in #48
The text was updated successfully, but these errors were encountered: