Код: Выделить всё
FileWriter fw = null;
FileReader fr = null;
try {
if (!new File(filePath).exists()) {
requiredStrings = CommandUtils.invoke(filename);
fw = new FileWriter(filePath);
fw.write(requiredStrings);
} else {
StringBuilder sb = new StringBuilder();
fr = new FileReader(filePath);
char[] buffer = new char[BLOCK_READ_SIZE];
int bytesRead;
while (-1 != (bytesRead = fr.read(buffer, 0, BLOCK_READ_SIZE))) {
sb.append(buffer, 0, bytesRead);
}
requiredStrings = sb.toString();
}
} finally {
if (fw != null) {
fw.close();
}
if (fr != null) {
fr.close();
}
}
return requiredStrings;
Оставшиеся обязательства {Reader x 1, Writer x-1>
Подробнее здесь: https://stackoverflow.com/questions/189 ... obligation
Мобильная версия