Всем привет. Написал данное решение, но выдает ошибку. Пишет, что не закрыл поток записи. Вроде в 38 строке это делаю
package com.javarush.task.task18.task1827;
import java.io.*;
/*
Прайсы
*/
public class Solution {
private static int getMaxId(String fileName) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String name = reader.readLine();
int maxId = 0;
int currentId;
String line;
while ((line = reader.readLine()) != null) {
currentId = Integer.parseInt(line.substring(0, 8).trim());
if (currentId > maxId) maxId = currentId;
}
reader.close();
return maxId;
}
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String fileName = reader.readLine();
String id = null;
String product = null;
double price = 0.0d;
int quantity = 0;
if (args.length == 4 && args[0].equals("-c")) {
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileName, true)));
id = String.valueOf(getMaxId(fileName.substring(0, 8) + 1));
product = args[1].substring(0, 30);
price = Double.parseDouble(args[2].substring(0, 8));
quantity = Integer.parseInt(args[3].substring(0, 4));
bw.write(id + product + price + quantity);
bw.close();
}
reader.close();
}
}